ホーム > 今日のテストコード > Google Chart APIを使ってQRコードを生成する

Google Chart APIを使ってQRコードを生成する

QRコードの生成にGoogle Chart APIを使ってみました。
rspec-railsのhave_tagマッチャを使うときはassert_selectのドキュメントを見ながらの場合が多いですね。早く覚えてしまいたい。
tech-memo
app/helpers/chart_helper.rb

1
2
3
4
5
6
7
8
9
10
11
12
13
14
module ChartHelper
 
  def qr_code_tag(text, options = {})
    param = { 
      :cht => 'qr',
      :chl => text
    }
    param[:chs] = options.delete(:chart_size) || '120x120'
    uri = URI::HTTP.build(:host => 'chart.apis.google.com', :path => '/chart', :query => param.to_query)
 
    image_tag uri.to_s, options
  end
 
end

spec/helpers/chart_helper_spec.rb

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
require 'spec_helper'
 
describe ChartHelper do
 
  it '指定したテキストを含むQRコードを得られること' do
    tag = helper.qr_code_tag('http://tech.hapicky.com/')
    expected_src = 'http://chart.apis.google.com/chart?chl=http%3A%2F%2Ftech.hapicky.com%2F&chs=120x120&cht=qr'
    tag.should have_tag('img[src=?]', expected_src)
  end
 
  it 'サイズ指定できること' do
    tag = helper.qr_code_tag('http://tech.hapicky.com/', :chart_size => '300x300')
    expected_src = 'http://chart.apis.google.com/chart?chl=http%3A%2F%2Ftech.hapicky.com%2F&chs=300x300&cht=qr'
    tag.should have_tag('img[src=?]', expected_src)
  end
 
  it 'altの指定ができること' do
    tag = helper.qr_code_tag('http://tech.hapicky.com/', :alt => 'tech-memo')
    expected_src = 'http://chart.apis.google.com/chart?chl=http%3A%2F%2Ftech.hapicky.com%2F&chs=120x120&cht=qr'
    tag.should have_tag('img[src=?][alt=tech-memo]', expected_src)
  end
 
end

参考:

  1. 2020 年 7 月 31 日 15:31 | #1

    You are so awesome! I do not believe I’ve truly read through something like that before. So good to find another person with unique thoughts on this topic. Really.. thanks for starting this up. This website is one thing that is needed on the internet, someone with a little originality!

  2. 2020 年 7 月 31 日 15:31 | #2

    Oh my goodness! Amazing article dude! Thank you so much, However I am encountering troubles with your RSS. I don’t know the reason why I am unable to subscribe to it. Is there anybody having identical RSS problems? Anybody who knows the answer can you kindly respond? Thanks!!

  3. 2020 年 7 月 31 日 15:34 | #3

    After checking out a few of the blog articles on your website, I seriously appreciate your way of writing a blog. I book-marked it to my bookmark website list and will be checking back in the near future. Take a look at my web site too and let me know what you think.

  4. 2020 年 7 月 31 日 15:38 | #4

    this hyperlink webpage on the main page

  5. 2020 年 7 月 31 日 15:41 | #5

    Great article. I will be facing a few of these issues as well..

  6. 2020 年 7 月 31 日 15:54 | #6

    Good web site you have got here.. It’s hard to find high-quality writing like yours nowadays. I seriously appreciate people like you! Take care!!

  7. 2020 年 7 月 31 日 16:01 | #7

    Having read this I believed it was really informative. I appreciate you spending some time and effort to put this article together. I once again find myself spending a lot of time both reading and posting comments. But so what, it was still worthwhile!

  8. 2020 年 7 月 31 日 17:00 | #8

    my blog website here basics

  9. 2020 年 7 月 31 日 18:06 | #9

    funny post sell find more info

  10. 2020 年 7 月 31 日 19:26 | #10

    This site really has all of the info I needed concerning this subject and didn’t know who to ask.

  11. 2020 年 7 月 31 日 19:33 | #11

    Having read this I believed it was rather informative. I appreciate you finding the time and energy to put this short article together. I once again find myself spending a lot of time both reading and leaving comments. But so what, it was still worthwhile!

  12. 2020 年 7 月 31 日 19:36 | #12

    I absolutely love your blog.. Great colors & theme. Did you build this website yourself? Please reply back as I’m looking to create my own site and would like to find out where you got this from or what the theme is called. Thank you!

  13. 2020 年 7 月 31 日 19:58 | #13

    Oh my goodness! Amazing article dude! Thank you, However I am experiencing difficulties with your RSS. I don’t know why I am unable to subscribe to it. Is there anybody else having identical RSS issues? Anybody who knows the solution can you kindly respond? Thanks!!

  14. 2020 年 7 月 31 日 20:47 | #14

    you can look here have a peek at this site bonuses

  15. 2020 年 7 月 31 日 20:57 | #15

    Great information. Lucky me I recently found your website by accident (stumbleupon). I have saved it for later!

  16. 2020 年 7 月 31 日 21:23 | #16

    A fascinating discussion is worth comment. I believe that you ought to write more on this topic, it might not be a taboo matter but typically people do not discuss these issues. To the next! Kind regards!!

  17. 2020 年 7 月 31 日 21:26 | #17

    Wow, incredible blog layout! How long have you been blogging for?
    you made blogging look easy. Thee overall look of your web site iss excellent,
    as well as the content!
    site

  18. 2020 年 7 月 31 日 21:36 | #18

    Oh my goodness! Incredible article dude! Thanks, However I am encountering difficulties with your RSS. I don’t know why I can’t join it. Is there anybody else having the same RSS problems? Anyone that knows the answer will you kindly respond? Thanks!!

  19. 2020 年 7 月 31 日 22:26 | #19

    click here Website Website

  20. 2020 年 7 月 31 日 23:12 | #20

    Regards. Numerous posts. order viagra

  21. 2020 年 7 月 31 日 23:22 | #21

    this hyperlink click over here now inquiry

  22. 2020 年 8 月 1 日 01:11 | #22

    Extra resources look at more info useful link

  23. 2020 年 8 月 1 日 01:42 | #23

    I blog often and I really appreciate your information. Your article has really peaked my interest. I will bookmark your website and keep checking for new details about once per week. I subscribed to your RSS feed too.

  24. 2020 年 8 月 1 日 01:48 | #24

    This web site really has all of the information I wanted concerning this subject and didn’t know who to ask.

  25. 2020 年 8 月 1 日 01:53 | #25

    Can I just say what a comfort to uncover a person that genuinely understands what they’re discussing on the net. You definitely understand how to bring an issue to light and make it important. More people ought to check this out and understand this side of your story. I can’t believe you aren’t more popular because you most certainly possess the gift.

  26. 2020 年 8 月 1 日 02:13 | #26

    I have fun with, result in I discovered just what I used to be taking
    a look for. You’ve ended my four day lengthy hunt! God Bless
    you man. Have a great day. Bye

  27. 2020 年 8 月 1 日 02:27 | #27

    An intriguing discussion is worth comment. I do think that you ought to write more on this issue, it might not be a taboo matter but usually folks don’t talk about such topics. To the next! Best wishes!!

  28. 2020 年 8 月 1 日 02:30 | #28

    you can try these out next like this

  29. 2020 年 8 月 1 日 03:00 | #29

    Wonderful knowledge. Cheers. viagra online

  30. 2020 年 8 月 1 日 03:06 | #30

    Good post. I learn something totally new and challenging on websites I stumbleupon every day. It’s always useful to read through articles from other writers and use something from other web sites.

  31. 2020 年 8 月 1 日 03:15 | #31

    Good article. I will be going through some of these issues as well..

  32. 2020 年 8 月 1 日 03:18 | #32

    Diverse lipid-savvy stores comprise already treated the system where platelets syndrome in their families in a freshly voided specimen. real casino online real money online casinos usa

  33. 2020 年 8 月 1 日 03:19 | #33

    Nice post. I learn something new and challenging on sites I stumbleupon every day. It’s always interesting to read content from other writers and use a little something from other sites.

  34. 2020 年 8 月 1 日 03:56 | #34

    company website look at this browse around this web-site

  35. 2020 年 8 月 1 日 04:03 | #35

    It’s an remarkable post for all the web viewers; they will obtain benefit from it
    I am sure.

  36. 2020 年 8 月 1 日 04:13 | #36

    I’ve learn several just right stuff here. Definitely
    value bookmarking for revisiting. I surprise how much effort
    you put to create any such excellent informative web
    site.

  37. 2020 年 8 月 1 日 04:52 | #37

    Hey! I could have sworn I’ve been to this blog
    before but after checking through some of the post I realized
    it’s new to me. Nonetheless, I’m definitely happy I found it and
    I’ll be bookmarking and checking back frequently!

  38. 2020 年 8 月 1 日 05:11 | #38

    check over here use this link this website

  39. 2020 年 8 月 1 日 05:28 | #39

    I’m now not certain the place you’re getting your information,
    however good topic. I must spend some time studying much
    more or figuring out more. Thanks for excellent information I
    used to be on the lookout for this information for my
    mission.

  40. 2020 年 8 月 1 日 06:51 | #40

    like it continued continue reading

  41. 2020 年 8 月 1 日 08:08 | #41

    get more image source click over here now

  42. 2020 年 8 月 1 日 09:18 | #42

    I’m gone to inform my little brother, that he should also pay a visit
    this website on regular basis to get updated from latest reports.

  43. 2020 年 8 月 1 日 09:22 | #43

    more.. More Bonuses made my day

  44. 2020 年 8 月 1 日 10:15 | #44

    why not find out more my link why not try here

  45. 2020 年 8 月 1 日 10:32 | #45

    You actually expressed it terrifically. cialis generic

  46. 2020 年 8 月 1 日 13:36 | #46

    Wonderful article! We are linking to this particularly great post on our site. Keep up the good writing.

  47. 2020 年 8 月 1 日 13:37 | #47

    Hello there! I could have sworn I’ve visited this website before but after browsing through some of the posts I realized it’s new to me. Anyways, I’m certainly happy I stumbled upon it and I’ll be bookmarking it and checking back regularly!

  48. 2020 年 8 月 1 日 13:43 | #48

    That is a good tip especially to those fresh to the blogosphere. Brief but very precise info… Thank you for sharing this one. A must read post!

  49. 2020 年 8 月 1 日 13:46 | #49

    An impressive share! I’ve just forwarded this onto a coworker who had been doing a little research on this. And he in fact ordered me breakfast simply because I found it for him… lol. So allow me to reword this…. Thank YOU for the meal!! But yeah, thanks for spending time to talk about this subject here on your site.

  50. 2020 年 8 月 1 日 14:33 | #50

    Hiya very cool website!! Man .. Beautiful .. Amazing .. I’ll bookmark your website and take the feeds additionally?
    I am happy to search out numerous helpful information right here within the
    submit, we’d like develop more strategies in this regard,
    thanks for sharing. . . . . .

コメントページ
1 132 133 134 135 136 151 353
  1. 2020 年 4 月 14 日 09:11 | #1
  2. 2020 年 4 月 20 日 13:42 | #2
  3. 2020 年 4 月 21 日 03:49 | #3
  4. 2020 年 4 月 25 日 14:25 | #4
  5. 2020 年 4 月 26 日 06:40 | #5
  6. 2020 年 4 月 30 日 01:19 | #6
  7. 2020 年 5 月 11 日 06:44 | #7
  8. 2020 年 7 月 1 日 21:07 | #8
  9. 2020 年 7 月 11 日 18:51 | #9
  10. 2020 年 7 月 14 日 04:59 | #10
  11. 2020 年 7 月 26 日 19:36 | #11
  12. 2020 年 7 月 29 日 21:50 | #12
  13. 2020 年 8 月 8 日 11:57 | #13