ホーム > 今日のテストコード > 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 年 8 月 14 日 22:20 | #1

    I want to to thank you for this fantastic read!! I certainly enjoyed every little bit of it. I’ve got you bookmarked to check out new stuff you post…

  2. 2020 年 8 月 14 日 22:29 | #2

    I do not know if it’s just me or if everybody else encountering issues with
    your website. It appears as if some of the written text on your posts are running off the screen. Can somebody else please comment and let me know if this is happening
    to them as well? This might be a issue with my browser because I’ve had this happen before.

    Thanks

  3. 2020 年 8 月 14 日 22:43 | #3

    Howdy! I could have sworn I’ve visited this web site before but after looking at some of the posts I realized it’s new to me. Anyways, I’m certainly delighted I discovered it and I’ll be book-marking it and checking back regularly!

  4. 2020 年 8 月 14 日 22:48 | #4

    Hi! I simply want to offer you a huge thumbs up for the excellent info you have right here on this post. I will be returning to your blog for more soon.

  5. 2020 年 8 月 14 日 22:59 | #5

    You are so awesome! I do not believe I have read a single thing like this before. So wonderful to find someone with a few genuine thoughts on this issue. Really.. thanks for starting this up. This website is one thing that is needed on the internet, someone with some originality!

  6. 2020 年 8 月 14 日 23:01 | #6

    Thanks in support of sharing such a pleasant opinion, article
    is pleasant, thats why i have read it entirely

  7. 2020 年 8 月 14 日 23:35 | #7

    Greetings! Very useful advice in this particular article! It is the little changes that produce the biggest changes. Many thanks for sharing!

  8. 2020 年 8 月 14 日 23:57 | #8

    After looking at a handful of the blog articles on your web page, I truly appreciate your way of blogging. I bookmarked it to my bookmark webpage list and will be checking back soon. Take a look at my web site too and let me know what you think.

  9. 2020 年 8 月 15 日 00:08 | #9

    Hi, I do think this is an excellent blog. I stumbledupon it ;) I may revisit once again since I saved as a favorite it. Money and freedom is the best way to change, may you be rich and continue to guide others.

  10. 2020 年 8 月 15 日 00:15 | #10

    I’m extremely pleased to discover this site. I wanted to thank you for your time for this fantastic read!! I definitely savored every part of it and I have you saved to fav to check out new stuff in your website.

  11. 2020 年 8 月 15 日 00:34 | #11

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

  12. 2020 年 8 月 15 日 00:42 | #12

    Good info. Lucky me I ran across your site by chance (stumbleupon). I have book-marked it for later!

  13. 2020 年 8 月 15 日 00:50 | #13

    Aw, this was an incredibly good post. Finding the time and actual effort to make a good article… but what can I say… I put things off a whole lot and never manage to get nearly anything done.

  14. 2020 年 8 月 15 日 00:54 | #14

    Good blog post. I absolutely appreciate this site. Thanks!

  15. 2020 年 8 月 15 日 01:02 | #15

    Thanks for finally writing about >tech-memo » Google Chart APIを使ってQRコードを生成する <Loved it!

  16. 2020 年 8 月 15 日 01:02 | #16

    Hello there! I could have sworn I’ve been to this web site before but after looking at many of the articles I realized it’s new to me. Nonetheless, I’m certainly delighted I discovered it and I’ll be book-marking it and checking back regularly!

  17. 2020 年 8 月 15 日 01:11 | #17

    When I originally commented I seem to have clicked on the -Notify me when new comments are added- checkbox and from now on each time a comment is added I receive four emails with the same comment. Perhaps there is an easy method you are able to remove me from that service? Thank you!

  18. 2020 年 8 月 15 日 01:19 | #18

    The very next time I read a blog, I hope that it doesn’t disappoint me as much as this one. I mean, I know it was my choice to read, but I genuinely believed you would probably have something interesting to say. All I hear is a bunch of moaning about something you could fix if you weren’t too busy searching for attention.

  19. 2020 年 8 月 15 日 01:42 | #19

    There’s definately a lot to know about this subject. I like all of the points you’ve made.

  20. 2020 年 8 月 15 日 02:10 | #20

    cheap canadian pharmacy online cialis generic https://wisig.org/

  21. 2020 年 8 月 15 日 02:19 | #21

    You are so awesome! I don’t believe I have read through a single thing like that before. So nice to find somebody with a few unique thoughts on this subject matter. Seriously.. many thanks for starting this up. This website is one thing that is needed on the web, someone with some originality!

  22. 2020 年 8 月 15 日 02:27 | #22

    Everything is very open with a very clear explanation of the issues. It was really informative. Your website is very useful. Thanks for sharing!

  23. 2020 年 8 月 15 日 02:44 | #23

    Way cool! Some very valid points! I appreciate you writing this write-up plus the rest of the site is very good.

  24. 2020 年 8 月 15 日 03:13 | #24

    You made some good points there. I looked on the net to learn more about the issue and found most individuals will go along with your views on this website.

  25. 2020 年 8 月 15 日 03:28 | #25

    Howdy! This blog post could not be written any better! Looking at this post reminds me of my previous roommate! He always kept preaching about this. I most certainly will send this information to him. Pretty sure he will have a very good read. Many thanks for sharing!

  26. 2020 年 8 月 15 日 03:29 | #26

    Hi, I do believe this is a great blog. I stumbledupon it ;) I am going to return yet again since i have saved as a favorite it. Money and freedom is the greatest way to change, may you be rich and continue to guide others.

  27. 2020 年 8 月 15 日 03:33 | #27

    I am sure this article has touched all the internet users, its really really fastidious paragraph on building up new blog.

  28. 2020 年 8 月 15 日 03:38 | #28

    You should take part in a contest for one of the most useful blogs on the internet. I will highly recommend this blog!

  29. 2020 年 8 月 15 日 04:12 | #29

    This page truly has all of the information and facts I needed concerning this subject and didn’t know who to ask.

  30. 2020 年 8 月 15 日 04:22 | #30

    Having read this I thought it was rather enlightening. I appreciate you taking the time and effort to put this informative article together. I once again find myself personally spending a significant amount of time both reading and posting comments. But so what, it was still worthwhile!

  31. 2020 年 8 月 15 日 04:31 | #31

    It’s nearly impossible to find experienced people on this topic, but you sound like you know what you’re talking about! Thanks

  32. 2020 年 8 月 15 日 04:34 | #32

    Way cool! Some very valid points! I appreciate you writing this write-up and also the rest of the website is extremely good.

  33. 2020 年 8 月 15 日 04:34 | #33

    Spot on with this write-up, I truly believe that this amazing site needs much more attention. I’ll probably be returning to see more, thanks for the advice!

  34. 2020 年 8 月 15 日 04:49 | #34

    Good article. I’m going through some of these issues as well..

  35. 2020 年 8 月 15 日 04:49 | #35

    Good information. Lucky me I ran across your blog by chance (stumbleupon). I’ve book-marked it for later!

  36. 2020 年 8 月 15 日 04:52 | #36

    Having read this I thought it was extremely informative. I appreciate you spending some time and energy to put this informative article together. I once again find myself spending way too much time both reading and leaving comments. But so what, it was still worthwhile!

  37. 2020 年 8 月 15 日 05:13 | #37

    You have made some good points there. I checked on the net to learn more about the issue and found most people will go along with your views on this website.

  38. 2020 年 8 月 15 日 05:14 | #38

    When I originally left a comment I appear to have clicked on the -Notify me when new comments are added- checkbox and from now on every time a comment is added I recieve four emails with the exact same comment. Is there a way you can remove me from that service? Thanks!

  39. 2020 年 8 月 15 日 05:17 | #39

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

  40. 2020 年 8 月 15 日 05:31 | #40

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

  41. 2020 年 8 月 15 日 05:38 | #41

    I have to thank you for the efforts you’ve put in penning this site. I really hope 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 very own website now ;)

  42. 2020 年 8 月 15 日 05:42 | #42

    hydroxychloroquine autophagy https://webbfenix.com/

  43. 2020 年 8 月 15 日 07:35 | #43

    Spot on with this write-up, I absolutely believe this site needs
    a lot more attention. I’ll probably be returning to see more, thanks for the
    advice!

  44. 2020 年 8 月 15 日 07:39 | #44

    Ergometer or buy off cialis online tinpot and deflated a scaled. generic Persantine Mxuuqo avjgec

  45. 2020 年 8 月 15 日 07:39 | #45

    Pulmonary canada dispensary online, ED can develop to improved control and urine as. buy ivermectin online Afemub kpmlgc

  46. 2020 年 8 月 15 日 07:40 | #46

    I want to express thanks to you just for rescuing me from such a condition. As a result of browsing throughout the the net and getting principles that were not pleasant, I figured my entire life was over. Being alive without the solutions to the difficulties you have resolved by means of your main short post is a crucial case, as well as ones which may have negatively affected my entire career if I hadn’t discovered your website. Your own ability and kindness in controlling every item was precious. I don’t know what I would have done if I had not discovered such a stuff like this. I am able to at this time look ahead to my future. Thank you very much for your skilled and effective guide. I won’t hesitate to propose the sites to any person who needs and wants support about this area.

コメントページ
1 149 150 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