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

ルーティングのテスト

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 年 3 月 10 日 04:25 | #1

    I simply want to mention I am just newbie to blogging and really enjoyed this website. More than likely I’m want to bookmark your blog . You actually come with wonderful posts. With thanks for revealing your blog site.

  2. 2020 年 3 月 12 日 17:01 | #2

    You should take part in a contest for one of the greatest websites on the web. I most certainly will highly recommend this blog!

  3. 2020 年 3 月 12 日 23:15 | #3

    Pretty! This was an incredibly wonderful article. Thanks for supplying these details.

  4. 2020 年 3 月 13 日 02:45 | #4

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

  5. 2020 年 3 月 13 日 02:46 | #5

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

  6. 2020 年 3 月 13 日 03:07 | #6

    Very good post. I’m facing a few of these issues as well..

  7. 2020 年 3 月 13 日 04:31 | #7

    Excellent web site you have here.. It’s difficult to find high-quality writing like yours nowadays. I honestly appreciate people like you! Take care!!

  8. 2020 年 3 月 13 日 04:32 | #8

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

  9. 2020 年 3 月 13 日 04:43 | #9

    Saved as a favorite, I really like your site!

  10. 2020 年 3 月 13 日 05:13 | #11

    This site was… how do I say it? Relevant!! Finally I have found something that helped me. Many thanks!

  11. 2020 年 3 月 13 日 05:40 | #12

    Good post. I certainly love this website. Keep it up!

  12. 2020 年 3 月 13 日 05:58 | #13

    Right here is the perfect web site for anybody who would like to understand this topic. You understand a whole lot its almost hard to argue with you (not that I actually will need to…HaHa). You certainly put a new spin on a topic that’s been written about for decades. Wonderful stuff, just great!

  13. 2020 年 3 月 13 日 06:00 | #14

    Oh my goodness! Incredible article dude! Thank you so much, However I am going through issues with your RSS. I don’t understand the reason why I am unable to join it. Is there anybody having identical RSS problems? Anyone that knows the solution can you kindly respond? Thanks!!

  14. 2020 年 3 月 13 日 06:01 | #15

    Greetings! Very useful advice in this particular post! It’s the little changes that will make the biggest changes. Thanks a lot for sharing!

  15. 2020 年 3 月 13 日 06:24 | #16

    After I initially left a comment I appear to have clicked the -Notify me when new comments are added- checkbox and now whenever a comment is added I get four emails with the same comment. Perhaps there is an easy method you can remove me from that service? Thank you!

  16. 2020 年 3 月 13 日 07:35 | #17

    May I simply say what a relief to find somebody that really understands what they’re discussing online. You definitely understand how to bring an issue to light and make it important. A lot more people ought to check this out and understand this side of your story. I was surprised you are not more popular since you certainly possess the gift.

  17. 2020 年 3 月 13 日 07:48 | #18

    Your style is very unique in comparison to other people I’ve read stuff from. Thank you for posting when you have the opportunity, Guess I’ll just bookmark this page.

  18. 2020 年 3 月 13 日 07:58 | #19

    A fascinating discussion is definitely worth comment. I do think that you should publish more about this topic, it may not be a taboo subject but usually people don’t discuss these subjects. To the next! Many thanks!!

  19. 2020 年 3 月 13 日 08:15 | #20

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

  20. 2020 年 3 月 13 日 09:03 | #22

    I need to to thank you for this excellent read!! I certainly loved every bit of it. I’ve got you bookmarked to check out new things you post…

  21. 2020 年 3 月 13 日 09:06 | #23

    Good info. Lucky me I found your site by chance (stumbleupon). I have saved as a favorite for later!

  22. 2020 年 3 月 13 日 09:23 | #24

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

  23. 2020 年 3 月 13 日 09:25 | #25

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

  24. 2020 年 3 月 13 日 09:55 | #26

    I must thank you for the efforts you have put in penning this website. I really hope to view the same high-grade content by you in the future as well. In truth, your creative writing abilities has inspired me to get my own blog now ;)

  25. 2020 年 3 月 13 日 10:01 | #27

    You ought to be a part of a contest for one of the finest blogs on the net. I most certainly will highly recommend this website!

  26. 2020 年 3 月 13 日 10:01 | #28

    Hi, I believe your web site may be having web browser compatibility problems. When I take a look at your web site in Safari, it looks fine however, if opening in IE, it’s got some overlapping issues. I just wanted to give you a quick heads up! Aside from that, wonderful site!

  27. 2020 年 3 月 13 日 10:07 | #29

    You’re so cool! I do not suppose I’ve read anything like this before. So great to find someone with a few unique thoughts on this subject matter. Seriously.. thank you for starting this up. This website is one thing that is needed on the web, someone with a little originality!

  28. 2020 年 3 月 13 日 10:25 | #30

    Hi there! I simply wish to give you a huge thumbs up for the excellent information you have right here on this post. I am returning to your site for more soon.

  29. 2020 年 3 月 13 日 10:30 | #31

    Very good post. I am going through some of these issues as well..

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

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

  31. 2020 年 3 月 13 日 13:01 | #33

    That is a great tip particularly to those fresh to the blogosphere. Simple but very precise information… Many thanks for sharing this one. A must read article!

  32. 2020 年 3 月 13 日 13:21 | #34

    An outstanding share! I’ve just forwarded this onto a friend who was conducting a little homework on this. And he actually bought me breakfast simply because I found it for him… lol. So let me reword this…. Thanks for the meal!! But yeah, thanx for spending some time to discuss this subject here on your web site.

  33. 2020 年 3 月 13 日 14:31 | #35

    This website definitely has all of the information and facts I wanted about this subject and didn’t know who to ask.

  34. 2020 年 3 月 13 日 14:45 | #36

    I’m amazed, I must say. Seldom do I come across a blog that’s both equally educative and entertaining, and without a doubt, you’ve hit the nail on the head. The problem is something that too few men and women are speaking intelligently about. I am very happy that I found this in my hunt for something concerning this.

  35. 2020 年 3 月 13 日 15:14 | #37

    You have made some good points there. I checked on the internet to find out more about the issue and found most individuals will go along with your views on this web site.

  36. 2020 年 3 月 13 日 15:20 | #38

    Very good article. I certainly appreciate this site. Stick with it!

  37. 2020 年 3 月 13 日 15:24 | #39

    I was able to find good advice from your blog articles.

  38. 2020 年 3 月 13 日 16:57 | #40

    Can I simply say what a comfort to discover someone that actually understands what they’re discussing online. You definitely know how to bring an issue to light and make it important. More and more people need to check this out and understand this side of your story. I can’t believe you are not more popular since you surely possess the gift.

  39. 2020 年 3 月 13 日 17:06 | #41

    Your style is really unique compared to other folks I have read stuff from. Many thanks for posting when you’ve got the opportunity, Guess I’ll just bookmark this blog.

  40. 2020 年 3 月 13 日 17:08 | #42

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

  41. 2020 年 3 月 13 日 18:09 | #44

    Can I just say what a comfort to uncover an individual who truly understands what they’re talking about online. You certainly realize how to bring a problem to light and make it important. More and more people need to check this out and understand this side of the story. It’s surprising you aren’t more popular because you definitely possess the gift.

  42. 2020 年 3 月 13 日 18:43 | #45

    Can I just say what a relief to find somebody who really understands what they are discussing online. You certainly know how to bring a problem to light and make it important. More and more people have to check this out and understand this side of the story. I was surprised that you’re not more popular because you surely possess the gift.

  43. 2020 年 3 月 13 日 19:49 | #46

    Can I just say what a relief to discover somebody that genuinely knows what they’re talking about online. You certainly realize how to bring an issue to light and make it important. A lot more people should read this and understand this side of your story. It’s surprising you aren’t more popular given that you definitely have the gift.

  44. 2020 年 3 月 13 日 20:08 | #47

    You are so interesting! I don’t suppose I’ve truly read anything like this before. So good to find somebody with some unique thoughts on this subject matter. Really.. thanks for starting this up. This web site is something that is required on the web, someone with a little originality!

  45. 2020 年 3 月 13 日 20:17 | #48

    Oh my goodness! Amazing article dude! Thank you so much, However I am experiencing difficulties with your RSS. I don’t know why I cannot join it. Is there anybody else getting the same RSS issues? Anyone that knows the solution can you kindly respond? Thanx!!

  46. 2020 年 3 月 13 日 20:21 | #49

    When I initially left a comment I appear to have clicked on the -Notify me when new comments are added- checkbox and now whenever a comment is added I get 4 emails with the same comment. There has to be a means you can remove me from that service? Many thanks!

  47. 2020 年 3 月 13 日 20:26 | #50

    I could not refrain from commenting. Very well written!

コメントページ
1 2 3 257 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