ホーム > 今日のテストコード > ルーティングのテスト

ルーティングのテスト

railsのルーティングのテスト。
:id => /\d+/ と指定している部分「これじゃ部分一致では?」と思いましたが、ActionController::Routing::Route#generation_requirements で\Aと\Zで挟まれて再コンパイルされてますね。

config/routes.rb

1
2
3
4
5
6
ActionController::Routing::Routes.draw do |map|
  map.with_options(:controller => 'products') do |products|
    products.connect 'products/:id', :action => 'show', :id => /\d+/
    products.connect 'products', :action => 'create', :conditions => { :method => :post }
  end
end

spec/controllers/products_controller_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
24
25
26
27
28
29
30
31
32
33
34
35
36
require 'spec_helper'
 
describe ProductsController do
 
  describe 'ルーティングのテスト' do
 
    it 'Products#show' do
      params_from(:get, '/products/123').should == { 
        :controller => 'products',
        :action => 'show',
        :id => '123'
      }
    end
 
    it 'idが数字のみでない場合は404' do
      lambda { 
        params_from(:get, '/products/123abc')
      }.should raise_error(ActionController::RoutingError)
    end
 
    it 'Product#create' do
      params_from(:post, '/products').should == { 
        :controller => 'products',
        :action => 'create'
      }
    end
 
    it 'createはPOSTのみ' do
      lambda { 
        params_from(:get, '/products')
      }.should raise_error(ActionController::MethodNotAllowed)
    end
 
  end
 
end

参考:

  1. 2020 年 6 月 30 日 21:57 | #1

    Hey there! I simply wish to give you a huge thumbs up for your excellent information you have here on this post. I will be coming back to your website for more soon.

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

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

  3. 2020 年 6 月 30 日 22:07 | #3

    Very nice blog post. I definitely appreciate this website. Keep writing!

  4. 2020 年 6 月 30 日 22:09 | #4

    It’s hard to find educated people for this subject, however, you sound like you know what you’re talking about! Thanks

  5. 2020 年 6 月 30 日 22:10 | #5
  6. 2020 年 6 月 30 日 22:12 | #6

    Greetings! Very helpful advice in this particular post! It’s the little changes which will make the biggest changes. Many thanks for sharing!

  7. 2020 年 6 月 30 日 22:13 | #7

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

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

    Wonderful post! We are linking to this great content on our website. Keep up the good writing.

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

    This is the right blog for everyone who hopes to find out about this topic. You realize so much its almost tough to argue with you (not that I personally would want to…HaHa). You certainly put a new spin on a subject that’s been written about for ages. Wonderful stuff, just wonderful!

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

    Very nice post. I certainly appreciate this website. Continue the good work!

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

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

  12. 2020 年 6 月 30 日 22:31 | #12

    After going over a number of the blog posts on your blog, I truly appreciate your technique of writing a blog. I book marked it to my bookmark website list and will be checking back soon. Take a look at my web site as well and tell me what you think.

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

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

  14. 2020 年 6 月 30 日 22:35 | #14

    Howdy! This article could not be written any better! Going through this post reminds me of my previous roommate! He constantly kept talking about this. I will send this article to him. Fairly certain he’s going to have a great read. Many thanks for sharing!

  15. 2020 年 6 月 30 日 22:37 | #15

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

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

    It’s difficult to find knowledgeable people about this topic, but you sound like you know what you’re talking about! Thanks

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

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

  18. 2020 年 6 月 30 日 22:41 | #18
  19. 2020 年 6 月 30 日 22:42 | #19

    After checking out a few of the articles on your web page, I seriously appreciate your technique of writing a blog. I book-marked it to my bookmark website list and will be checking back in the near future. Please check out my web site as well and tell me what you think.

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

    I wanted to thank you for this good read!! I certainly enjoyed every little bit of it. I have you book marked to check out new stuff you post…

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

    I truly love your website.. Very nice colors & theme. Did you make this web site yourself? Please reply back as I’m planning to create my own personal website and would like to learn where you got this from or what the theme is called. Thanks!

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

    This is a topic which is close to my heart… Take care! Exactly where are your contact details though?

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

    I couldn’t resist commenting. Exceptionally well written!

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

    I seriously love your website.. Pleasant colors & theme. Did you develop this amazing site yourself? Please reply back as I’m looking to create my very own site and would like to learn where you got this from or just what the theme is called. Many thanks!

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

    There is definately a lot to find out about this topic. I love all the points you’ve made.

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

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

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

    Your style is so unique in comparison to other people I’ve read stuff from. I appreciate you for posting when you’ve got the opportunity, Guess I will just bookmark this blog.

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

    You are so awesome! I do not believe I have read something like this before. So great to find somebody with a few unique thoughts on this subject matter. Seriously.. many thanks for starting this up. This site is one thing that is needed on the web, someone with a little originality!

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

    You need to take part in a contest for one of the greatest sites on the net. I’m going to recommend this web site!

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

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

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

    Your style is unique compared to other people I have read stuff from. Thank you for posting when you’ve got the opportunity, Guess I will just bookmark this web site.

  32. 2020 年 6 月 30 日 23:15 | #32

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

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

    It’s nearly impossible to find knowledgeable people for this topic, but you seem like you know what you’re talking about! Thanks

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

    An intriguing discussion is definitely worth comment. There’s no doubt that that you need to publish more about this topic, it may not be a taboo matter but generally people don’t talk about such issues. To the next! All the best!!

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

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

  36. 2020 年 6 月 30 日 23:31 | #36

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

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

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

  38. 2020 年 6 月 30 日 23:41 | #38

    Good info. Lucky me I ran across your blog by accident (stumbleupon). I have saved it for later!

  39. 2020 年 6 月 30 日 23:43 | #39

    Greetings! Very helpful advice in this particular article! It is the little changes that produce the biggest changes. Thanks for sharing!

  40. 2020 年 6 月 30 日 23:43 | #40

    Next time I read a blog, Hopefully it won’t disappoint me just as much as this one. I mean, I know it was my choice to read through, nonetheless I really thought you would have something useful to talk about. All I hear is a bunch of whining about something that you can fix if you were not too busy searching for attention.

  41. 2020 年 6 月 30 日 23:44 | #41

    Your style is so unique compared to other folks I’ve read stuff from. Thanks for posting when you’ve got the opportunity, Guess I’ll just book mark this page.

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

    Everything is very open with a precise clarification of the challenges. It was truly informative. Your website is very helpful. Many thanks for sharing!

  43. 2020 年 6 月 30 日 23:46 | #43

    You’re so awesome! I do not suppose I’ve read through a single thing like this before. So wonderful to find another person with some original thoughts on this subject matter. Seriously.. thank you for starting this up. This web site is one thing that is required on the web, someone with a little originality!

  44. 2020 年 6 月 30 日 23:46 | #44

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

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

    After looking over a handful of the blog posts on your web site, I honestly appreciate your way of writing a blog. I saved it to my bookmark webpage list and will be checking back soon. Please check out my web site too and let me know what you think.

  46. 2020 年 6 月 30 日 23:54 | #46

    Oh my goodness! Incredible article dude! Thank you, However I am having troubles with your RSS. I don’t know the reason why I am unable to subscribe to it. Is there anyone else having the same RSS issues? Anyone who knows the answer will you kindly respond? Thanx!!

  47. 2020 年 6 月 30 日 23:54 | #47

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

  48. 2020 年 6 月 30 日 23:56 | #48

    It’s hard to come by knowledgeable people on this topic, but you seem like you know what you’re talking about! Thanks

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

    Great information. Lucky me I recently found your site by chance (stumbleupon). I’ve saved it for later!

  50. 2020 年 7 月 1 日 00:03 | #50

    I want to to thank you for this good read!! I absolutely loved every bit of it. I have got you bookmarked to look at new stuff you post…

コメントページ
1 223 224 225 226 227 256 389
  1. 2020 年 4 月 14 日 18:25 | #1
  2. 2020 年 4 月 20 日 10:04 | #2
  3. 2020 年 4 月 30 日 12:33 | #3
  4. 2020 年 5 月 5 日 15:03 | #4
  5. 2020 年 5 月 5 日 18:45 | #5
  6. 2020 年 5 月 9 日 18:45 | #6
  7. 2020 年 7 月 1 日 21:54 | #7