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

    I absolutely love your blog.. Pleasant colors & theme. Did you make this amazing site yourself? Please reply back as I’m attempting to create my own website and would like to know where you got this from or exactly what the theme is called. Cheers!

  2. 2020 年 6 月 29 日 21:18 | #2

    An outstanding share! I’ve just forwarded this onto a colleague who has been conducting a little homework on this. And he in fact bought me dinner simply because I found it for him… lol. So allow me to reword this…. Thanks for the meal!! But yeah, thanx for spending time to talk about this topic here on your blog.

  3. 2020 年 6 月 29 日 21:26 | #3

    Everyone loves it whenever people come together and share thoughts. Great site, stick with it!

  4. 2020 年 6 月 29 日 21:28 | #4

    I love it whenever people get together and share opinions. Great blog, keep it up!

  5. 2020 年 6 月 29 日 21:31 | #5

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

  6. 2020 年 6 月 29 日 21:49 | #6

    http://www.jewelrypandora.org/ Pandora Jewelry Official Site

  7. 2020 年 6 月 29 日 23:36 | #7

    http://www.pandora-outlet.us.org/ Pandora Outlet Online

  8. 2020 年 6 月 29 日 23:38 | #8

    You need to be a part of a contest for one of the greatest blogs on the net. I am going to highly recommend this site!

  9. 2020 年 6 月 29 日 23:46 | #9

    I needed to thank you for this good read!! I certainly loved every little bit of it. I have got you bookmarked to check out new stuff you post…

  10. 2020 年 6 月 30 日 00:13 | #10

    After going over a few of the blog posts on your web site, I truly like your technique of blogging. I book marked it to my bookmark website list and will be checking back soon. Please visit my web site as well and let me know how you feel.

  11. 2020 年 6 月 30 日 00:15 | #11

    Excellent blog you’ve got here.. It’s difficult to find high-quality writing like yours these days. I honestly appreciate people like you! Take care!!

  12. 2020 年 6 月 30 日 00:30 | #12

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

  13. 2020 年 6 月 30 日 00:41 | #13

    Good post. I am going through many of these issues as well..

  14. 2020 年 6 月 30 日 00:45 | #14

    I couldn’t refrain from commenting. Very well written!

  15. 2020 年 6 月 30 日 00:56 | #15

    After checking out a number of the articles on your site, I truly like your technique 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 as well and let me know what you think.

  16. 2020 年 6 月 30 日 00:59 | #16

    Hey there! I simply want to offer you a big thumbs up for your excellent info you have right here on this post. I’ll be returning to your blog for more soon.

  17. 2020 年 6 月 30 日 01:29 | #17

    Having read this I believed it was very enlightening. I appreciate you finding the time and energy to put this informative article together. I once again find myself spending way too much time both reading and posting comments. But so what, it was still worth it!

  18. 2020 年 6 月 30 日 01:32 | #18

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

  19. 2020 年 6 月 30 日 01:33 | #19

    I absolutely love your site.. Great colors & theme. Did you make this site yourself? Please reply back as I’m trying to create my own personal site and want to learn where you got this from or just what the theme is named. Cheers!

  20. 2020 年 6 月 30 日 02:01 | #20

    Excellent blog post. I definitely appreciate this site. Thanks!

  21. 2020 年 6 月 30 日 02:21 | #21

    I seriously love your site.. Very nice colors & theme. Did you make this website yourself? Please reply back as I’m attempting to create my very own site and would love to learn where you got this from or what the theme is named. Appreciate it!

  22. 2020 年 6 月 30 日 02:25 | #22

    Nice post. I learn something totally new and challenging on websites I stumbleupon every day. It’s always exciting to read content from other writers and practice something from their web sites.

  23. 2020 年 6 月 30 日 02:42 | #23

    Good article. I am going through a few of these issues as well..

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

    Kxdtdk koslux viagra samples Order viagra

  25. 2020 年 6 月 30 日 07:02 | #25
  26. 2020 年 6 月 30 日 07:39 | #26

    A different issue is that video gaming became one of the all-time most important forms of entertainment for people of all ages. Kids engage in video games, and also adults do, too. Your XBox 360 is among the favorite video games systems for many who love to have hundreds of games available to them, as well as who like to experiment with live with other people all over the world. Thank you for sharing your ideas.

  27. 2020 年 6 月 30 日 12:52 | #27

    Spot on with this write-up, I absolutely think this website needs much more attention. I’ll probably be back again to read through more, thanks for the information!

  28. 2020 年 6 月 30 日 12:56 | #28

    Hello.This post was really motivating, particularly since I was looking for thoughts on this issue last Sunday.

  29. 2020 年 6 月 30 日 13:01 | #29

    Hi, i think that i saw you visited my web site so i came to “return the favor”.I’m trying to find things to enhance my web site!I suppose its ok to use some of your ideas!!

  30. 2020 年 6 月 30 日 13:06 | #30

    I blog frequently and I truly appreciate your information. This great article has truly peaked my interest. I will book mark your site and keep checking for new details about once a week. I subscribed to your RSS feed too.

  31. 2020 年 6 月 30 日 13:07 | #31

    Hello, i think that i saw you visited my blog so i came to “return the favor”.I am trying to find things to improve my site!I suppose its ok to use some of your ideas!!

  32. 2020 年 6 月 30 日 13:12 | #32

    Good day! I could have sworn I’ve visited this website before but after browsing through some of the articles 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!

  33. 2020 年 6 月 30 日 13:23 | #33

    Howdy, I believe your blog could be having web browser compatibility problems. Whenever I look at your blog in Safari, it looks fine however, when opening in Internet Explorer, it has some overlapping issues. I simply wanted to provide you with a quick heads up! Other than that, fantastic website!

  34. 2020 年 6 月 30 日 13:24 | #34

    Oh my goodness! Impressive article dude! Thank you so much, However I am having troubles with your RSS. I don’t understand why I am unable to subscribe to it. Is there anybody else having the same RSS issues? Anyone who knows the answer can you kindly respond? Thanks!!

  35. 2020 年 6 月 30 日 13:35 | #35

    Next time I read a blog, I hope that it won’t disappoint me as much as this particular one. I mean, Yes, it was my choice to read, nonetheless I genuinely believed you would have something helpful to talk about. All I hear is a bunch of complaining about something that you could possibly fix if you were not too busy looking for attention.

  36. 2020 年 6 月 30 日 13:38 | #36

    You are so cool! I don’t believe I’ve truly read something like this before. So great to discover someone with some unique thoughts on this subject. Really.. many thanks for starting this up. This website is one thing that is needed on the internet, someone with a bit of originality!

  37. 2020 年 6 月 30 日 13:41 | #37

    You are so awesome! I don’t suppose I have read something like that before. So good to find another person with a few unique thoughts on this subject. Really.. thanks for starting this up. This site is something that is needed on the web, someone with some originality!

  38. 2020 年 6 月 30 日 13:48 | #38

    Your style is unique in comparison to other people I have read stuff from. Many thanks for posting when you have the opportunity, Guess I will just book mark this page.

  39. 2020 年 6 月 30 日 13:51 | #39

    Yiqazi bqpoel loan for bad credit payday advance

  40. 2020 年 6 月 30 日 13:51 | #40

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

  41. 2020 年 6 月 30 日 13:56 | #41

    I really love your blog.. Very nice colors & theme. Did you create this web 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 exactly what the theme is called. Thank you!

  42. 2020 年 6 月 30 日 14:05 | #42

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

  43. 2020 年 6 月 30 日 14:56 | #43

    That is a good tip particularly to those fresh to the blogosphere. Brief but very precise info… Appreciate your sharing this one. A must read post!

  44. 2020 年 6 月 30 日 15:05 | #44

    I’m amazed, I must say. Seldom do I come across a blog that’s both educative and amusing, and without a doubt, you’ve hit the nail on the head. The problem is something not enough folks are speaking intelligently about. Now i’m very happy that I found this during my hunt for something relating to this.

  45. 2020 年 6 月 30 日 15:09 | #45

    Kskxol ndrtvu ocean casino online nj betfair casino online nj

  46. 2020 年 6 月 30 日 15:27 | #46

    This is the perfect webpage for anybody who really wants to find out about this topic. You realize a whole lot its almost tough to argue with you (not that I personally would want to…HaHa). You definitely put a new spin on a topic that has been discussed for many years. Wonderful stuff, just wonderful!

  47. 2020 年 6 月 30 日 16:34 | #47

    This site was… how do you say it? Relevant!! Finally I have found something which helped me. Thank you!

  48. 2020 年 6 月 30 日 16:47 | #48

    Excellent blog you have got here.. It’s difficult to find high quality writing like yours nowadays. I truly appreciate people like you! Take care!!

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

    When I originally left a comment I appear to have clicked on the -Notify me when new comments are added- checkbox and now every time a comment is added I get four emails with the same comment. Perhaps there is a means you are able to remove me from that service? Many thanks!

  50. 2020 年 6 月 30 日 17:04 | #50

    Aw, this was an extremely nice post. Taking a few minutes and actual effort to generate a really good article… but what can I say… I put things off a whole lot and don’t seem to get anything done.

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