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

ルーティングのテスト

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 年 7 月 1 日 00:29 | #1

    I in addition to my buddies appeared to be examining the nice points on your web blog and unexpectedly came up with a terrible suspicion I had not thanked the site owner for those tips. All the men had been certainly stimulated to study all of them and already have undoubtedly been loving those things. Thank you for turning out to be very considerate and also for pick out varieties of amazing subjects millions of individuals are really eager to be aware of. My very own honest regret for not expressing gratitude to sooner.

  2. 2020 年 7 月 1 日 00:47 | #2
  3. 2020 年 7 月 1 日 01:33 | #3

    Great article. I will be going through some of these issues as well..

  4. 2020 年 7 月 1 日 01:37 | #4

    I seriously love your site.. Excellent colors & theme. Did you make this website yourself? Please reply back as I’m hoping to create my own site and want to learn where you got this from or what the theme is named. Many thanks!

  5. 2020 年 7 月 1 日 01:45 | #5

    Right here is the right site for everyone who wishes to understand this topic. You realize so much its almost tough to argue with you (not that I really will need to…HaHa). You certainly put a brand new spin on a topic that has been discussed for ages. Great stuff, just wonderful!

  6. 2020 年 7 月 1 日 01:48 | #6

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

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

    Good post. I learn something new and challenging on blogs I stumbleupon on a daily basis. It will always be interesting to read articles from other writers and practice a little something from their websites.

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

    Excellent post. I absolutely love this website. Keep it up!

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

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

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

    Saved as a favorite, I love your site!

  11. 2020 年 7 月 1 日 01:53 | #11

    An impressive share! I’ve just forwarded this onto a colleague who has been doing a little homework on this. And he in fact bought me breakfast simply because I found 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 blog.

  12. 2020 年 7 月 1 日 01:57 | #12

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

  13. 2020 年 7 月 1 日 01:59 | #13

    Right here is the perfect webpage for anyone who wishes to understand this topic. You realize so much its almost tough to argue with you (not that I actually will need to…HaHa). You certainly put a new spin on a subject that’s been discussed for years. Excellent stuff, just wonderful!

  14. 2020 年 7 月 1 日 02:01 | #14

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

  15. 2020 年 7 月 1 日 02:04 | #15

    This page really has all the information I needed about this subject and didn’t know who to ask.

  16. 2020 年 7 月 1 日 02:05 | #16

    Having read this I believed it was extremely enlightening. I appreciate you spending some time and effort to put this informative article together. I once again find myself spending a lot of time both reading and leaving comments. But so what, it was still worthwhile!

  17. 2020 年 7 月 1 日 02:06 | #17

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

  18. 2020 年 7 月 1 日 02:17 | #18

    Spot on with this write-up, I honestly feel this website needs a lot more attention. I’ll probably be back again to see more, thanks for the information!

  19. 2020 年 7 月 1 日 02:25 | #19

    Can I just say what a comfort to uncover someone who actually understands what they are talking about on the net. You definitely know how to bring a problem to light and make it important. A lot more people must look at this and understand this side of the story. It’s surprising you are not more popular since you certainly possess the gift.

  20. 2020 年 7 月 1 日 02:26 | #20

    Pretty! This was an incredibly wonderful post. Thank you for providing this info.

  21. 2020 年 7 月 1 日 02:26 | #21

    I want to to thank you for this excellent read!! I definitely loved every bit of it. I’ve got you bookmarked to look at new things you post…

  22. 2020 年 7 月 1 日 02:30 | #22

    Hello there! This blog post could not be written much better! Reading through this post reminds me of my previous roommate! He constantly kept preaching about this. I’ll forward this information to him. Pretty sure he’ll have a great read. Many thanks for sharing!

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

    It’s hard to come by experienced people about this subject, however, you seem like you know what you’re talking about! Thanks

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

    The next time I read a blog, Hopefully it does not fail me as much as this particular one. After all, I know it was my choice to read, but I truly believed you would have something helpful to say. All I hear is a bunch of moaning about something that you could possibly fix if you weren’t too busy searching for attention.

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

    You should take part in a contest for one of the most useful blogs online. I most certainly will recommend this blog!

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

    I’m amazed, I must say. Seldom do I come across a blog that’s both equally educative and entertaining, and let me tell you, you’ve hit the nail on the head. The issue is something too few folks are speaking intelligently about. I am very happy I came across this in my search for something regarding this.

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

    I must thank you for the efforts you’ve put in penning this website. I am hoping to view the same high-grade blog posts from you later on as well. In fact, your creative writing abilities has inspired me to get my own, personal website now ;)

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

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

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

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

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

    Can I simply just say what a relief to find someone that actually understands what they’re discussing online. You definitely know how to bring a problem to light and make it important. More people have to look at this and understand this side of the story. It’s surprising you are not more popular since you most certainly possess the gift.

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

    You’ve made some decent points there. I checked on the web to learn more about the issue and found most people will go along with your views on this site.

  32. 2020 年 7 月 1 日 02:47 | #32

    Oh my goodness! Awesome article dude! Thanks, However I am going through troubles with your RSS. I don’t understand the reason why I cannot subscribe to it. Is there anybody else having similar RSS problems? Anybody who knows the answer will you kindly respond? Thanx!!

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

    Right here is the perfect site for everyone who really wants to find out about this topic. You know so much its almost hard to argue with you (not that I actually would want to…HaHa). You definitely put a brand new spin on a topic which has been written about for years. Excellent stuff, just wonderful!

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

    An impressive share! I have just forwarded this onto a friend who has been doing a little research on this. And he in fact ordered me dinner because I found it for him… lol. So let me reword this…. Thanks for the meal!! But yeah, thanks for spending time to talk about this subject here on your website.

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

    Very nice article. I definitely appreciate this site. Thanks!

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

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

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

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

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

    After looking into a number of the blog posts on your site, I truly like your way of writing a blog. I bookmarked it to my bookmark webpage list and will be checking back soon. Please check out my web site as well and let me know how you feel.

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

    I blog often and I truly thank you for your information. The article has truly peaked my interest. I am going to book mark your blog and keep checking for new information about once per week. I subscribed to your Feed as well.

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

    Nice post. I learn something new and challenging on websites I stumbleupon everyday. It’s always interesting to read through articles from other authors and use something from other web sites.

  41. 2020 年 7 月 1 日 03:01 | #41

    Hi there! I simply want to offer you a huge thumbs up for the excellent info you have got right here on this post. I am coming back to your web site for more soon.

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

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

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

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

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

    Excellent article. I will be dealing with many of these issues as well..

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

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

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

    Good post. I learn something totally new and challenging on websites I stumbleupon every day. It’s always interesting to read articles from other authors and practice something from other sites.

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

    Good post. I learn something new and challenging on blogs I stumbleupon everyday. It’s always interesting to read through articles from other authors and practice a little something from their sites.

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

    When I initially left a comment I appear to have clicked the -Notify me when new comments are added- checkbox and from now on whenever a comment is added I receive 4 emails with the same comment. Is there a means you can remove me from that service? Kudos!

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

    Having read this I believed it was really enlightening. I appreciate you taking the time and effort to put this content together. I once again find myself personally spending a lot of time both reading and posting comments. But so what, it was still worthwhile!

コメントページ
1 224 225 226 227 228 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