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

    great put up, very informative. I wonder why the opposite experts
    of this sector don’t notice this. You should proceed your writing.
    I’m confident, you’ve a great readers’ base already!

  2. 2020 年 8 月 1 日 15:00 | #2

    Thank you for each of your labor on this website. My mum really loves getting into research and it’s really easy to see why. We learn all relating to the lively ways you provide informative tips and hints on this blog and in addition inspire participation from people on that topic then our own simple princess is really discovering so much. Take pleasure in the remaining portion of the year. You are carrying out a fantastic job.

  3. 2020 年 8 月 1 日 15:08 | #3

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

  4. 2020 年 8 月 1 日 15:14 | #4

    Nice post. I learn something new and challenging on blogs I stumbleupon on a daily basis. It will always be exciting to read content from other authors and practice something from their websites.

  5. 2020 年 8 月 1 日 16:12 | #5

    An outstanding share! I’ve just forwarded this onto
    a coworker who had been doing a little research on this.
    And he actually ordered me lunch due to the fact that I stumbled upon it for
    him… lol. So let me reword this…. Thank YOU for
    the meal!! But yeah, thanx for spending the
    time to talk about this topic here on your internet
    site.

  6. 2020 年 8 月 1 日 16:37 | #6

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

  7. 2020 年 8 月 1 日 16:37 | #7

    There’s definately a lot to know about this issue. I really like all of the points you have made.

  8. 2020 年 8 月 1 日 16:43 | #8

    Good post. I learn something new and challenging on sites I stumbleupon on a daily basis. It will always be interesting to read content from other writers and practice a little something from other web sites.

  9. 2020 年 8 月 1 日 16:47 | #9

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

  10. 2020 年 8 月 1 日 17:25 | #10

    The very next time I read a blog, I hope that 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 useful to say. All I hear is a bunch of whining about something you could possibly fix if you weren’t too busy looking for attention.

  11. 2020 年 8 月 1 日 18:00 | #11

    Very good write-up. I absolutely appreciate this website. Continue the good work!

  12. 2020 年 8 月 1 日 18:01 | #12

    Hello there! This post couldn’t be written any better! Reading through this post reminds me of my previous roommate! He always kept talking about this. I’ll forward this article to him. Fairly certain he will have a very good read. Thank you for sharing!

  13. 2020 年 8 月 1 日 18:13 | #13

    Hello there! I could have sworn I’ve been to this blog before but after looking at some of the posts I realized it’s new to me. Nonetheless, I’m definitely pleased I discovered it and I’ll be book-marking it and checking back regularly!

  14. 2020 年 8 月 1 日 18:53 | #14

    I was recommended this web site by my cousin. I
    am not sure whether this post is written by him as no one else know such detailed about my difficulty.

    You’re wonderful! Thanks!

  15. 2020 年 8 月 1 日 20:25 | #15

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

  16. 2020 年 8 月 1 日 20:59 | #16

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

  17. 2020 年 8 月 1 日 21:05 | #17

    I’m impressed, I have to admit. Seldom do I encounter a blog that’s equally educative and interesting, and without a doubt, you have hit the nail on the head. The issue is an issue that too few men and women are speaking intelligently about. Now i’m very happy I stumbled across this in my search for something concerning this.

  18. 2020 年 8 月 1 日 22:00 | #18

    Hello there! This post couldn’t be written much better! Looking at this post reminds me of my previous roommate! He always kept talking about this. I’ll forward this article to him. Pretty sure he’s going to have a good read. I appreciate you for sharing!

  19. 2020 年 8 月 1 日 22:29 | #19

    I really like it when people come together and share opinions. Great blog, keep it up!

  20. 2020 年 8 月 1 日 23:16 | #20

    from this source other continued

  21. 2020 年 8 月 1 日 23:45 | #21

    Facial fretfulness who had been reported in Onlooker War I. online casinos usa best online casino real money

  22. 2020 年 8 月 2 日 00:04 | #22

    You’re so awesome! I do not believe I have read a single thing like this before. So good to find another person with original thoughts on this topic. Seriously.. many thanks for starting this up. This web site is one thing that’s needed on the web, someone with a little originality!

  23. 2020 年 8 月 2 日 00:10 | #23

    You made some really 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 web site.

  24. 2020 年 8 月 2 日 00:14 | #24

    I was excited to find this website. I need to to thank you for ones time for this wonderful read!! I definitely enjoyed every bit of it and I have you saved to fav to look at new stuff on your blog.

  25. 2020 年 8 月 2 日 00:27 | #25

    visit here see this page visit the website

  26. 2020 年 8 月 2 日 00:49 | #26

    I’m impressed, I have to admit. Rarely do I come across a blog that’s both educative and amusing, and without a doubt, you have hit the nail on the head. The problem is something which too few men and women are speaking intelligently about. I’m very happy that I found this during my hunt for something relating to this.

  27. 2020 年 8 月 2 日 01:02 | #27

    My spouse and I stumbled over here coming from a different web
    address and thought I may as well check things out.

    I like what I see so i am just following you.
    Look forward to looking into your web page for a second time.

  28. 2020 年 8 月 2 日 01:28 | #28

    That is a great tip particularly to those fresh to the blogosphere. Simple but very accurate info… Thanks for sharing this one. A must read article!

  29. 2020 年 8 月 2 日 02:17 | #29

    navigate to this site her comment is here you can check here

  30. 2020 年 8 月 2 日 02:57 | #30

    I needed to thank you for this good read!! I absolutely enjoyed every bit of it. I have got you saved as a favorite to check out new things you post…

  31. 2020 年 8 月 2 日 03:01 | #31

    A motivating discussion is worth comment. There’s no doubt that that you need to publish more about this subject matter, it might not be a taboo subject but usually people do not talk about these subjects. To the next! All the best!!

  32. 2020 年 8 月 2 日 03:05 | #32

    After looking at a few of the articles on your web page, I truly appreciate your technique of writing a blog. I added it to my bookmark website list and will be checking back in the near future. Please check out my website as well and let me know how you feel.

  33. 2020 年 8 月 2 日 03:08 | #33

    Very good article. I am dealing with many of these issues as well..

  34. 2020 年 8 月 2 日 03:24 | #34

    read more here More Help love it

  35. 2020 年 8 月 2 日 03:50 | #35

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

  36. 2020 年 8 月 2 日 04:26 | #36

    Very good info. Lucky me I discovered your site by accident (stumbleupon). I’ve saved it for later!

  37. 2020 年 8 月 2 日 04:36 | #37

    Hello! I could have sworn I’ve visited this site before but after going through many of the articles I realized it’s new to me. Regardless, I’m definitely delighted I came across it and I’ll be bookmarking it and checking back often!

  38. 2020 年 8 月 2 日 04:40 | #38

    Hi there! 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 am going to forward this article to him. Pretty sure he’ll have a good read. I appreciate you for sharing!

  39. 2020 年 8 月 2 日 05:12 | #39

    If some one wants expert view concerning blogging and site-building afterward i propose him/her to go to see this web site, Keep up
    the good job.

  40. 2020 年 8 月 2 日 05:40 | #40

    Visit This Link you can find out more anchor

  41. 2020 年 8 月 2 日 06:19 | #41

    magnificent submit, very informative. I wonder why the other specialists of this sector don’t realize this.
    You must proceed your writing. I am sure, you’ve a huge readers’ base already!

  42. 2020 年 8 月 2 日 06:46 | #42

    more about the author hop over to this web-site informative post

  43. 2020 年 8 月 2 日 08:53 | #43

    his explanation our website over here

  44. 2020 年 8 月 2 日 08:56 | #44

    Thanks a lot for giving everyone an extraordinarily marvellous chance to check tips from here. It really is very terrific and as well , stuffed with amusement for me and my office peers to search your blog at minimum three times per week to learn the fresh issues you will have. And of course, we are usually motivated considering the mind-blowing knowledge you serve. Certain 1 points on this page are really the most efficient we have all ever had.

  45. 2020 年 8 月 2 日 09:00 | #45

    Have you ever considered about adding a little bit more than just your articles?
    I mean, what you say is fundamental and everything. Nevertheless think
    of if you added some great graphics or videos to give your posts
    more, “pop”! Your content is excellent but with
    pics and clips, this website could undeniably be one of the greatest in its
    field. Wonderful blog!

  46. 2020 年 8 月 2 日 10:27 | #46

    blog here Clicking Here full report

  47. 2020 年 8 月 2 日 12:02 | #47

    read full report Bonuses navigate here

  48. 2020 年 8 月 2 日 13:33 | #48

    Bonuses directory click this over here now

  49. 2020 年 8 月 2 日 14:09 | #49

    Someone essentially assist to make critically
    articles I would state. That is the first time I frequented your website page and so far?
    I surprised with the research you made to create this particular submit amazing.
    Fantastic process!

  50. 2020 年 8 月 2 日 14:32 | #50

    Hi, I do think this is a great site. I stumbledupon it ;) I’m going to revisit yet again since I bookmarked it. Money and freedom is the greatest way to change, may you be rich and continue to help other people.

コメントページ
1 133 134 135 136 137 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