ホーム > 今日のテストコード > 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 年 5 月 29 日 23:16 | #1

    Wonderful post! We will be linking to this particularly great content on our website. Keep up the great writing.

  2. 2020 年 5 月 29 日 23:27 | #2

    There’s definately a great deal to find out about this topic. I really like all the points you have made.

  3. 2020 年 5 月 30 日 00:28 | #3

    I would like to thank you for the efforts you have put in writing this blog. I am hoping to view the same high-grade blog posts from you in the future as well. In truth, your creative writing abilities has encouraged me to get my own, personal site now ;)

  4. 2020 年 5 月 30 日 00:32 | #4

    May I simply just say what a comfort to uncover somebody who actually understands what they’re discussing on the web. You actually understand how to bring a problem to light and make it important. More people should read this and understand this side of your story. It’s surprising you’re not more popular because you certainly have the gift.

  5. 2020 年 5 月 30 日 00:42 | #5

    Hi, I do believe your web site could possibly be having web browser compatibility issues. When I look at your blog in Safari, it looks fine however when opening in I.E., it has some overlapping issues. I simply wanted to provide you with a quick heads up! Apart from that, fantastic blog!

  6. 2020 年 5 月 30 日 00:54 | #6

    Right here is the right blog for anybody who wants to find out about this topic. You understand a whole lot its almost hard to argue with you (not that I actually would want to…HaHa). You certainly put a brand new spin on a topic that’s been discussed for years. Excellent stuff, just excellent!

  7. 2020 年 5 月 30 日 01:07 | #7

    Spot on with this write-up, I actually believe that this web site needs a great deal more attention. I’ll probably be back again to see more, thanks for the information!

  8. 2020 年 5 月 30 日 01:22 | #8

    Hi there! I could have sworn I’ve been to this site before but after going through many of the articles I realized it’s new to me. Anyways, I’m certainly happy I came across it and I’ll be book-marking it and checking back often!

  9. 2020 年 5 月 30 日 01:46 | #9

    Way cool! Some very valid points! I appreciate you writing this post plus the rest of the website is also very good.

  10. 2020 年 5 月 30 日 01:58 | #10

    Good article. I definitely appreciate this site. Stick with it!

  11. 2020 年 5 月 30 日 03:16 | #11

    After going over a handful of the blog posts on your website, I honestly appreciate your technique of blogging. I saved as a favorite it to my bookmark webpage list and will be checking back in the near future. Please visit my web site too and let me know what you think.

  12. 2020 年 5 月 30 日 04:21 | #12

    You made some decent points there. I checked on the internet to find out more about the issue and found most people will go along with your views on this website.

  13. 2020 年 5 月 30 日 04:43 | #13

    Hi, I do believe this is an excellent web site. I stumbledupon it ;) I am going to come back yet again since i have bookmarked it. Money and freedom is the greatest way to change, may you be rich and continue to help others.

  14. 2020 年 5 月 30 日 04:56 | #14

    The next time I read a blog, I hope that it doesn’t fail me just as much as this particular one. After all, I know it was my choice to read, however I truly believed you would have something useful to say. All I hear is a bunch of crying about something you could possibly fix if you were not too busy seeking attention.

  15. 2020 年 5 月 30 日 06:09 | #15

    Spot on with this write-up, I actually feel this web site needs much more attention. I’ll probably be returning to see more, thanks for the information!

  16. 2020 年 5 月 30 日 06:10 | #16

    Thank you a lot for giving everyone such a superb possiblity to read critical reviews from here. It’s always very sweet and also packed with a great time for me and my office co-workers to search your web site at least thrice in one week to see the newest things you have. And indeed, I’m always amazed with your surprising guidelines you give. Some two ideas in this article are easily the most impressive I have had.

  17. 2020 年 5 月 30 日 06:47 | #17

    An outstanding share! I have just forwarded this onto a friend who has been doing a little homework on this. And he actually ordered me lunch because I found it for him… lol. So allow me to reword this…. Thank YOU for the meal!! But yeah, thanx for spending time to discuss this topic here on your web page.

  18. 2020 年 5 月 30 日 07:17 | #18

    hydroxychloroquine tablets uk https://hydroxychloroquine1st.com/

  19. 2020 年 5 月 30 日 07:38 | #19

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

  20. 2020 年 5 月 30 日 07:43 | #20

    A fascinating discussion is worth comment. I believe that you ought to publish more on this issue, it might not be a taboo matter but typically folks don’t talk about these topics. To the next! Many thanks!!

  21. 2020 年 5 月 30 日 07:47 | #21

    hydroxychloroquine 400mg tab https://hydroxychloroquine1st.com/

  22. 2020 年 5 月 30 日 08:05 | #22

    Good post. I learn something new and challenging on blogs I stumbleupon every day. It will always be helpful to read content from other writers and use something from other websites.

  23. 2020 年 5 月 30 日 09:30 | #23

    I blog frequently and I seriously thank you for your information. The article has truly peaked my interest. I will book mark your site and keep checking for new information about once a week. I opted in for your Feed as well.

  24. 2020 年 5 月 30 日 09:31 | #24

    You are so awesome! I do not think I have read something like that before. So nice to find someone with genuine thoughts on this subject. Seriously.. thank you for starting this up. This website is something that is required on the internet, someone with some originality!

  25. 2020 年 5 月 30 日 09:33 | #25

    I’m pretty pleased to uncover this page. I wanted to thank you for ones time due to this wonderful read!! I definitely loved every little bit of it and i also have you bookmarked to see new information on your site.

  26. 2020 年 5 月 30 日 09:49 | #26

    I like it when people come together and share thoughts. Great website, keep it up!

  27. 2020 年 5 月 30 日 09:56 | #27

    Spot on with this write-up, I seriously think this web site needs much more attention. I’ll probably be returning to see more, thanks for the advice!

  28. 2020 年 5 月 30 日 10:10 | #28

    Good post. I certainly appreciate this website. Keep it up!

  29. 2020 年 5 月 30 日 10:18 | #29

    bookmarked!!, I love your website!

  30. 2020 年 5 月 30 日 10:43 | #30

    Very good blog post. I absolutely appreciate this website. Keep it up!

  31. 2020 年 5 月 30 日 10:44 | #31

    hydroxychloroquine covid https://azhydroxychloroquine.com/

  32. 2020 年 5 月 30 日 10:51 | #32

    You need to be a part of a contest for one of the highest quality websites on the net. I most certainly will recommend this web site!

  33. 2020 年 5 月 30 日 11:09 | #33

    Igkusd vcxtel generic cialis 2020 non prescription ed pills

  34. 2020 年 5 月 30 日 11:29 | #34

    I’m amazed, I must say. Rarely do I encounter a blog that’s both equally educative and interesting, and let me tell you, you have hit the nail on the head. The problem is an issue that not enough men and women are speaking intelligently about. Now i’m very happy that I found this in my hunt for something regarding this.

  35. 2020 年 5 月 30 日 11:34 | #35

    There is certainly a lot to find out about this topic. I love all of the points you made.

  36. 2020 年 5 月 30 日 12:44 | #36

    Good day! I could have sworn I’ve visited your blog before but after looking at many of the articles I realized it’s new to me. Nonetheless, I’m definitely delighted I discovered it and I’ll be book-marking it and checking back frequently!

  37. 2020 年 5 月 30 日 13:07 | #37

    hydroxychloroquine price in india https://hydroxychloroquine1st.com/

  38. 2020 年 5 月 30 日 13:20 | #38

    You ought to take part in a contest for one of the finest websites online. I will highly recommend this website!

  39. 2020 年 5 月 30 日 14:05 | #39

    This is a great tip especially to those new to the blogosphere. Short but very precise info… Appreciate your sharing this one. A must read post!

  40. 2020 年 5 月 30 日 14:16 | #40

    It’s hard to come by knowledgeable people for this subject, but you sound like you know what you’re talking about! Thanks

  41. 2020 年 5 月 30 日 14:57 | #41

    Hi, I do believe this is an excellent web site. I stumbledupon it ;) I may revisit yet again since I book-marked it. Money and freedom is the greatest way to change, may you be rich and continue to help other people.

  42. 2020 年 5 月 30 日 15:18 | #42

    I just want to mention I am new to blogging and site-building and seriously enjoyed your web site. Very likely I’m want to bookmark your site . You certainly have very good well written articles. Bless you for sharing your web-site.

  43. 2020 年 5 月 30 日 16:00 | #43

    This is the perfect site for anyone who hopes to find out about this topic. You realize a whole lot its almost hard to argue with you (not that I personally will need to…HaHa). You definitely put a new spin on a topic which has been written about for a long time. Wonderful stuff, just great!

  44. 2020 年 5 月 30 日 16:54 | #44

    I was more than happy to find this page. I need to to thank you for ones time for this particularly wonderful read!! I definitely liked every bit of it and i also have you saved to fav to see new stuff on your blog.

  45. 2020 年 5 月 30 日 17:31 | #45

    Hi! I just would like to offer you a big thumbs up for the excellent information you have here on this post. I am coming back to your blog for more soon.

  46. 2020 年 5 月 30 日 18:44 | #46

    This is a topic that is near to my heart… Thank you! Exactly where are your contact details though?

  47. 2020 年 5 月 30 日 19:03 | #47

    Everyone loves it when people get together and share opinions. Great website, continue the good work!

  48. 2020 年 5 月 30 日 20:08 | #48

    You have made some good points there. I checked on the web for additional information about the issue and found most people will go along with your views on this website.

  49. 2020 年 5 月 30 日 20:14 | #49

    I was able to find good info from your content.

  50. 2020 年 5 月 30 日 20:15 | #50

    This is the right website for anybody who wants to understand this topic. You realize a whole lot its almost tough to argue with you (not that I personally will need to…HaHa). You certainly put a brand new spin on a subject that’s been written about for decades. Great stuff, just wonderful!

コメントページ
1 50 51 52 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