ホーム > 今日のテストコード > 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 年 3 月 10 日 06:33 | #1

    I just want to mention I am just all new to weblog and seriously savored you’re blog site. Likely I’m planning to bookmark your site . You definitely have very good posts. Thanks a bunch for revealing your website.

  2. 2020 年 3 月 13 日 10:47 | #2

    After looking at a handful of the blog posts on your site, I really appreciate your way of writing a blog. I book-marked it to my bookmark website list and will be checking back soon. Please check out my website too and tell me how you feel.

  3. 2020 年 3 月 14 日 01:29 | #3

    It was a real pleasure getting to your site a short while ago. I came here this day hoping to find out something new. And I was not upset. Your ideas about new solutions on this subject were helpful and a good help to me. Thank you for making time to write out these things as well as sharing your thinking.

  4. 2020 年 3 月 15 日 04:31 | #4

    Great info. Lucky me I ran across your blog by accident (stumbleupon). I’ve bookmarked it for later.

  5. 2020 年 3 月 15 日 05:34 | #5

    Yet were you aware this seduction strategies will not be only guys?

  6. 2020 年 3 月 15 日 13:12 | #6

    Pretty! This was an incredibly wonderful article. Many thanks for supplying these details.

  7. 2020 年 3 月 15 日 15:01 | #7

    I was really happy to find this web-site. I intended to thanks for your time for this fantastic read!! I most definitely delighting in every little of it and also I have you bookmarked to take a look at brand-new stuff you post.

  8. 2020 年 3 月 15 日 17:40 | #8

    Hello there! This blog post couldn’t be written any better! Looking through this article reminds me of my previous roommate! He continually kept talking about this. I am going to forward this article to him. Pretty sure he’ll have a good read. Thanks for sharing!

  9. 2020 年 3 月 16 日 01:11 | #9

    wireless headphones are the best because they do not have those bulky wires”

  10. 2020 年 3 月 16 日 02:55 | #10

    It’s nearly impossible to find well-informed people about this subject, but you seem like you know what you’re talking about! Thanks

  11. 2020 年 3 月 16 日 08:26 | #11

    I couldn’t resist commenting. Perfectly written.

  12. 2020 年 3 月 16 日 12:05 | #12

    After research study a few of the blog posts on your internet site now, and I genuinely like your method of blogging. I bookmarked it to my book mark website checklist and also will be inspecting back quickly. Pls have a look at my web site too and let me know what you think.

  13. 2020 年 3 月 16 日 16:25 | #13

    I was able to find good info from your blog articles.

  14. 2020 年 3 月 17 日 02:00 | #14

    When I initially commented I clicked the -Alert me when brand-new remarks are added- checkbox and now each time a comment is added I obtain four emails with the same comment. Exists any way you can eliminate me from that solution? Many thanks!

  15. 2020 年 3 月 17 日 07:57 | #15

    The very next time I read a blog, I hope that it doesn’t fail me as much as this particular one. After all, Yes, it was my choice to read through, nonetheless I genuinely believed you’d have something helpful to talk about. All I hear is a bunch of complaining about something that you can fix if you were not too busy searching for attention.

  16. 2020 年 3 月 17 日 13:41 | #16

    Faytech North America is a touch screen Manufacturer of both monitors and pcs. They specialize in the design, development, manufacturing and marketing of Capacitive touch screen, Resistive touch screen, Industrial touch screen, IP65 touch screen, touchscreen monitors and integrated touchscreen PCs. Contact them at http://www.faytech.us, 121 Varick Street, New York, NY 10013, +1 646 205 3214.

  17. 2020 年 3 月 17 日 21:50 | #17

    I your writing style really loving this site.

  18. 2020 年 3 月 18 日 08:34 | #18

    After research a few of the article on your site now, and I genuinely like your means of blogging. I bookmarked it to my book mark site listing as well as will certainly be examining back soon. Pls have a look at my website also as well as let me understand what you assume.

  19. 2020 年 3 月 18 日 13:28 | #19

    Faytech North America is a touch screen Manufacturer of both monitors and pcs. They specialize in the design, development, manufacturing and marketing of Capacitive touch screen, Resistive touch screen, Industrial touch screen, IP65 touch screen, touchscreen monitors and integrated touchscreen PCs. Contact them at http://www.faytech.us, 121 Varick Street, New York, NY 10013, +1 646 205 3214.

  20. 2020 年 3 月 18 日 17:14 | #20

    This is the best blog site for anyone who intends to find out about this subject. You realize a lot its almost hard to argue with you (not that I in fact would want?HaHa). You absolutely put a new spin on a topic thats been covered for years. Excellent stuff, just fantastic!

  21. 2020 年 3 月 19 日 13:50 | #21

    Good blog post. I absolutely appreciate this site. Stick with it!

  22. 2020 年 3 月 20 日 01:12 | #22

    Everything is very open with a really clear description of the issues. It was truly informative. Your website is very helpful. Many thanks for sharing.

  23. 2020 年 3 月 20 日 01:58 | #23

    Way cool! Some extremely valid points! I appreciate you penning this post plus the rest of the site is also really good.

  24. 2020 年 3 月 20 日 12:55 | #24

    It’s difficult to find educated people in this particular topic, but you seem like you know what you’re talking about! Thanks

  25. 2020 年 3 月 22 日 09:27 | #25

    This is a topic that is near to my heart… Cheers! Where are your contact details though?

  26. 2020 年 3 月 22 日 10:50 | #26

    There is noticeably a package to know about this. I think you made certain great factors in attributes additionally.

  27. 2020 年 3 月 23 日 12:06 | #27

    Your area is valueble for me. Thanks !?

  28. 2020 年 3 月 23 日 12:22 | #28

    Having read this I thought it was extremely enlightening. I appreciate you taking the time and energy to put this content together. I once again find myself spending a significant amount of time both reading and commenting. But so what, it was still worthwhile.

  29. 2020 年 3 月 23 日 21:25 | #29

    Your location is valueble for me. Many thanks !?

  30. 2020 年 3 月 24 日 00:09 | #30

    molecular docking of falcipain 2 and chloroquine

  31. 2020 年 3 月 24 日 06:35 | #31

    Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or something. I think that you can do with a few pics to drive the message home a little bit, but other than that, this is fantastic blog. An excellent read. I will definitely be back.

  32. 2020 年 3 月 24 日 07:55 | #32

    Hello! I simply wish to give you a huge thumbs up for your great information you have got here on this post. I am coming back to your website for more soon.

  33. 2020 年 3 月 24 日 15:18 | #33

    Oh my goodness! Amazing article dude! Thank you, However I am experiencing problems with your RSS. I don’t understand why I am unable to subscribe to it. Is there anybody getting identical RSS problems? Anybody who knows the answer can you kindly respond? Thanx!

  34. 2020 年 3 月 24 日 16:17 | #34

    Tremendous іssᥙes here. I ɑm very satisfied
    to seе your article. Thanks so much and І’m looking forward to contact you.
    Will you please drop me a e-mail?

  35. 2020 年 3 月 25 日 01:20 | #35

    Right here is the right webpage for anybody who wants to find out about this topic. You understand so much its almost hard to argue with you (not that I actually would want to…HaHa). You definitely put a fresh spin on a subject which has been discussed for many years. Excellent stuff, just wonderful.

  36. 2020 年 3 月 25 日 03:17 | #36

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

  37. 2020 年 3 月 25 日 13:59 | #37

    This website was… how do I say it? Relevant!! Finally I have found something that helped me. Cheers!

  38. 2020 年 3 月 25 日 23:20 | #38

    Hi, I do believe this is an excellent site. I stumbledupon it ;) I may return once again since I book marked it. Money and freedom is the best way to change, may you be rich and continue to help others.

  39. 2020 年 3 月 26 日 01:19 | #39

    You should take part in a contest for one of the highest quality blogs on the web. I am going to recommend this web site!

  40. 2020 年 3 月 26 日 13:24 | #40

    I love reading through an article that can make men and women think. Also, thanks for allowing for me to comment.

  41. 2020 年 3 月 27 日 21:28 | #41

    MetroClick specializes in building completely interactive products like Photo Booth for rental or sale, Touch Screen Kiosks, Large Touch Screen Displays , Monitors, Digital Signages and experiences. With our own hardware production facility and in-house software development teams, we are able to achieve the highest level of customization and versatility for Photo Booths, Touch Screen Kiosks, Touch Screen Monitors and Digital Signage. Visit MetroClick in NYC at http://www.metroclick.com/ or , 121 Varick St, New York, NY 10013, +1 646-843-0888.

  42. 2020 年 3 月 28 日 09:28 | #42

    This really answered my trouble, thank you!

  43. 2020 年 3 月 28 日 21:42 | #43

    Sapid Agency is a Search Engine Optimization company in New York City that provides SEO Services. Their proprietary SEO strategies help struggling websites and aspiring business owners to rank their websites higher in multiple search engines like Google , Yahoo and Bing. They provide local and gmb map ranking for businesses in NYC and many other local areas. Find more at https://www.sapidagency.com/ @ 145 E 57TH NEW YORK, NY 10022, USA, +1 971 341 5608 USA

  44. 2020 年 3 月 29 日 05:25 | #44

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

  45. 2020 年 3 月 30 日 01:07 | #45

    Nice post. I find out something a lot more tough on different blogs everyday. It will constantly be boosting to check out material from various other authors as well as practice a little something from their shop. I?d prefer to use some with the material on my blog whether you don?t mind. Natually I?ll provide you a link on your internet blog site. Many thanks for sharing.

  46. 2020 年 3 月 30 日 15:14 | #46

    Everything is very open with a clear description of the challenges. It was really informative. Your site is very useful. Thank you for sharing.

  47. 2020 年 4 月 2 日 12:34 | #47

    The next time I read a blog, Hopefully it doesn’t disappoint me just as much as this one. After all, Yes, it was my choice to read, however I truly believed you would have something useful to say. All I hear is a bunch of complaining about something that you could fix if you weren’t too busy seeking attention.

  48. 2020 年 4 月 3 日 14:45 | #48

    Excellent blog you’ve got here.. It’s hard to find high quality writing like yours nowadays. I really appreciate individuals like you! Take care!!

  49. 2020 年 4 月 4 日 21:49 | #49

    gross city [url=https://amstyles.com/#]ventolin inhaler without an rx[/url] anywhere
    class hopefully problem generic ventolin inhalers for sale
    originally resist ventolin inhaler without an rx without environment https://amstyles.com/

  50. 2020 年 4 月 5 日 07:15 | #50

    Galerimizdeki her seçkin Konya escortlari benzersizdir ve her karsilasmayi özel hale getirmek için çalisiyoruz , ancak biraz daha spesifik bir sey istiyorsaniz, bir noktaya kadar mecbur kaliyoruz.

コメントページ
1 2 3 102 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