ホーム > 今日のテストコード > 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 年 6 月 30 日 17:15 | #1

    This is a really good tip especially to those new to the blogosphere. Short but very accurate info… Thanks for sharing this one. A must read post!

  2. 2020 年 6 月 30 日 17:21 | #2

    Good post. I will be experiencing many of these issues as well..

  3. 2020 年 6 月 30 日 17:27 | #3

    This is a very good tip especially to those fresh to the blogosphere. Simple but very precise info… Many thanks for sharing this one. A must read article!

  4. 2020 年 6 月 30 日 17:34 | #4

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

  5. 2020 年 6 月 30 日 17:36 | #5

    Hi, I do believe this is a great blog. I stumbledupon it ;) I may return yet again since I book-marked it. Money and freedom is the best way to change, may you be rich and continue to help others.

  6. 2020 年 6 月 30 日 17:43 | #6

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

  7. 2020 年 6 月 30 日 17:59 | #7

    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.

  8. 2020 年 6 月 30 日 18:24 | #8
  9. 2020 年 6 月 30 日 18:31 | #9

    I would like to thank you for the efforts you’ve put in penning this site. I am hoping to view the same high-grade content from you in the future as well. In truth, your creative writing abilities has motivated me to get my very own site now ;)

  10. 2020 年 6 月 30 日 18:33 | #10

    Very good article. I am experiencing some of these issues as well..

  11. 2020 年 6 月 30 日 18:42 | #11

    I must thank you for the efforts you’ve put in penning this site. I am hoping to check out the same high-grade content from you later on as well. In truth, your creative writing abilities has motivated me to get my very own blog now ;)

  12. 2020 年 6 月 30 日 18:46 | #12

    This is the right web site for everyone who would like to understand this topic. You understand so much its almost hard to argue with you (not that I really will need to…HaHa). You definitely put a fresh spin on a topic which has been written about for decades. Wonderful stuff, just excellent!

  13. 2020 年 6 月 30 日 18:59 | #13

    I blog often and I genuinely thank you for your information. Your article has really peaked my interest. I will take a note of your site and keep checking for new details about once a week. I subscribed to your Feed as well.

  14. 2020 年 6 月 30 日 19:03 | #14

    I’m amazed, I must say. Seldom do I encounter a blog that’s equally educative and amusing, and let me tell you, you have hit the nail on the head. The problem is something too few folks are speaking intelligently about. I am very happy I found this in my search for something concerning this.

  15. 2020 年 6 月 30 日 21:31 | #15

    Good post. I learn something new and challenging on blogs I stumbleupon everyday. It’s always useful to read through content from other writers and use a little something from their web sites.

  16. 2020 年 6 月 30 日 21:43 | #16

    I needed to thank you for this very good read!! I certainly enjoyed every little bit of it. I’ve got you bookmarked to look at new things you post…

  17. 2020 年 6 月 30 日 22:03 | #17

    This is a topic that is close to my heart… Cheers! Exactly where are your contact details though?

  18. 2020 年 6 月 30 日 22:04 | #18

    Hello there! I could have sworn I’ve been to this website before but after going through some of the articles I realized it’s new to me. Anyhow, I’m certainly delighted I came across it and I’ll be bookmarking it and checking back regularly!

  19. 2020 年 6 月 30 日 22:08 | #19

    Next time I read a blog, Hopefully it does not disappoint me just as much as this particular one. After all, I know it was my choice to read, nonetheless I truly thought you would probably have something interesting to talk about. All I hear is a bunch of moaning about something that you can fix if you weren’t too busy searching for attention.

  20. 2020 年 6 月 30 日 22:16 | #20

    I absolutely love your site.. Pleasant colors & theme. Did you develop this site yourself? Please reply back as I’m planning to create my own personal blog and want to learn where you got this from or what the theme is named. Thanks!

  21. 2020 年 6 月 30 日 22:23 | #21

    When I initially commented 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 receive 4 emails with the same comment. Perhaps there is a means you are able to remove me from that service? Appreciate it!

  22. 2020 年 6 月 30 日 22:27 | #22

    An impressive share! I’ve just forwarded this onto a friend who was doing a little homework on this. And he in fact bought me dinner simply because I stumbled upon it for him… lol. So allow me to reword this…. Thank YOU for the meal!! But yeah, thanx for spending time to talk about this subject here on your blog.

  23. 2020 年 6 月 30 日 22:29 | #23

    That is a great tip particularly to those new to the blogosphere. Short but very accurate information… Thanks for sharing this one. A must read post!

  24. 2020 年 6 月 30 日 22:33 | #24

    Good article! We will be linking to this great content on our website. Keep up the great writing.

  25. 2020 年 6 月 30 日 23:18 | #25

    Aw, this was a very nice post. Spending some time and actual effort to create a top notch article… but what can I say… I put things off a lot and never seem to get nearly anything done.

  26. 2020 年 6 月 30 日 23:20 | #26

    The very next time I read a blog, Hopefully it won’t fail me as much as this particular one. I mean, Yes, it was my choice to read through, nonetheless I actually believed you’d have something interesting to talk about. All I hear is a bunch of moaning about something that you could possibly fix if you weren’t too busy seeking attention.

  27. 2020 年 6 月 30 日 23:34 | #27

    Can I just say what a relief to find someone who genuinely understands what they’re talking about online. You definitely know how to bring a problem to light and make it important. A lot more people need to check this out and understand this side of your story. I can’t believe you aren’t more popular because you certainly have the gift.

  28. 2020 年 6 月 30 日 23:35 | #28

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

  29. 2020 年 6 月 30 日 23:45 | #29

    Aw, this was an extremely good post. Taking the time and actual effort to create a good article… but what can I say… I put things off a lot and never manage to get anything done.

  30. 2020 年 6 月 30 日 23:55 | #30

    I wanted to thank you for this wonderful read!! I certainly enjoyed every little bit of it. I’ve got you book marked to look at new things you post…

  31. 2020 年 7 月 1 日 00:02 | #31

    There’s certainly a great deal to find out about this subject. I like all the points you’ve made.

  32. 2020 年 7 月 1 日 01:40 | #32

    An intriguing discussion is worth comment. I do think that you ought to publish more on this subject matter, it might not be a taboo matter but usually people don’t talk about these topics. To the next! Kind regards!!

  33. 2020 年 7 月 1 日 01:50 | #33

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

  34. 2020 年 7 月 1 日 01:52 | #34

    I used to be able to find good info from your articles.

  35. 2020 年 7 月 1 日 02:11 | #35

    After exploring a few of the blog articles on your site, I really appreciate your technique of writing a blog. I saved as a favorite it to my bookmark site list and will be checking back soon. Please visit my website too and let me know your opinion.

  36. 2020 年 7 月 1 日 02:13 | #36

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

  37. 2020 年 7 月 1 日 02:23 | #37

    Good site you’ve got here.. It’s hard to find high quality writing like yours these days. I truly appreciate individuals like you! Take care!!

  38. 2020 年 7 月 1 日 02:31 | #38

    Greetings! Very useful advice within this post! It’s the little changes which will make the most important changes. Thanks for sharing!

  39. 2020 年 7 月 1 日 02:33 | #39

    Aw, this was an extremely good post. Spending some time and actual effort to produce a very good article… but what can I say… I hesitate a lot and never manage to get nearly anything done.

  40. 2020 年 7 月 1 日 02:34 | #40

    I used to be able to find good advice from your blog posts.

  41. 2020 年 7 月 1 日 02:37 | #41

    Next time I read a blog, Hopefully it doesn’t disappoint me as much as this one. After all, Yes, it was my choice to read through, nonetheless I actually believed you would have something useful to say. All I hear is a bunch of crying about something you could fix if you were not too busy seeking attention.

  42. 2020 年 7 月 1 日 02:55 | #42

    I love it when people come together and share views. Great website, continue the good work!

  43. 2020 年 7 月 1 日 03:16 | #43

    This blog was… how do you say it? Relevant!! Finally I’ve found something that helped me. Thank you!

  44. 2020 年 7 月 1 日 03:20 | #44

    An outstanding share! I have just forwarded this onto a co-worker who was conducting a little research on this. And he actually ordered me lunch simply because I discovered it for him… lol. So let me reword this…. Thanks for the meal!! But yeah, thanx for spending time to talk about this matter here on your web site.

  45. 2020 年 7 月 1 日 03:39 | #45

    I simply need to notify you that I am new to blogging and really valued your website. More than likely I am prone to save your blog post . You certainly have memorable article material. Admire it for expressing with us your very own url webpage

  46. 2020 年 7 月 1 日 03:49 | #46

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

  47. 2020 年 7 月 1 日 03:55 | #47

    Greetings! Very useful advice in this particular article! It is the little changes that will make the largest changes. Thanks a lot for sharing!

  48. 2020 年 7 月 1 日 03:57 | #48

    An outstanding share! I have just forwarded this onto a co-worker who was doing a little homework on this. And he actually ordered me dinner due to the fact that I found it for him… lol. So let me reword this…. Thank YOU for the meal!! But yeah, thanx for spending time to talk about this subject here on your website.

  49. 2020 年 7 月 1 日 04:01 | #49

    I was excited to uncover this site. I wanted to thank you for your time just for this wonderful read!! I definitely enjoyed every bit of it and i also have you book-marked to look at new things on your website.

  50. 2020 年 7 月 1 日 04:25 | #50

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

コメントページ
1 92 93 94 95 96 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