rc_rails 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. data/.gitignore +7 -0
  2. data/CHANGELOG +355 -0
  3. data/Gemfile +5 -0
  4. data/Gemfile.lock.development +117 -0
  5. data/MIT-LICENSE +20 -0
  6. data/README.rdoc +71 -0
  7. data/Rakefile +33 -0
  8. data/Todo.txt +1 -0
  9. data/lib/rc_rails.rb +9 -0
  10. data/lib/resources_controller/actions.rb +147 -0
  11. data/lib/resources_controller/active_record/saved.rb +15 -0
  12. data/lib/resources_controller/helper.rb +123 -0
  13. data/lib/resources_controller/include_actions.rb +37 -0
  14. data/lib/resources_controller/named_route_helper.rb +154 -0
  15. data/lib/resources_controller/railtie.rb +14 -0
  16. data/lib/resources_controller/request_path_introspection.rb +83 -0
  17. data/lib/resources_controller/resource_methods.rb +32 -0
  18. data/lib/resources_controller/singleton_actions.rb +21 -0
  19. data/lib/resources_controller/specification.rb +119 -0
  20. data/lib/resources_controller/version.rb +3 -0
  21. data/lib/resources_controller.rb +849 -0
  22. data/resources_controller.gemspec +29 -0
  23. data/spec/app/database.yml +5 -0
  24. data/spec/app/views/accounts/show.html.erb +0 -0
  25. data/spec/app/views/addresses/edit.html.erb +0 -0
  26. data/spec/app/views/addresses/index.html.erb +0 -0
  27. data/spec/app/views/addresses/new.html.erb +0 -0
  28. data/spec/app/views/addresses/show.html.erb +0 -0
  29. data/spec/app/views/admin/forums/create.html.erb +0 -0
  30. data/spec/app/views/admin/forums/destroy.html.erb +0 -0
  31. data/spec/app/views/admin/forums/edit.html.erb +0 -0
  32. data/spec/app/views/admin/forums/index.html.erb +0 -0
  33. data/spec/app/views/admin/forums/new.html.erb +0 -0
  34. data/spec/app/views/admin/forums/show.html.erb +0 -0
  35. data/spec/app/views/admin/forums/update.html.erb +0 -0
  36. data/spec/app/views/comments/edit.html.erb +0 -0
  37. data/spec/app/views/comments/index.html.erb +0 -0
  38. data/spec/app/views/comments/new.html.erb +0 -0
  39. data/spec/app/views/comments/show.html.erb +0 -0
  40. data/spec/app/views/forum_posts/edit.html.erb +0 -0
  41. data/spec/app/views/forum_posts/index.html.erb +0 -0
  42. data/spec/app/views/forum_posts/new.html.erb +0 -0
  43. data/spec/app/views/forum_posts/show.html.erb +0 -0
  44. data/spec/app/views/forums/create.html.erb +0 -0
  45. data/spec/app/views/forums/destroy.html.erb +0 -0
  46. data/spec/app/views/forums/edit.html.erb +0 -0
  47. data/spec/app/views/forums/index.html.erb +0 -0
  48. data/spec/app/views/forums/new.html.erb +0 -0
  49. data/spec/app/views/forums/show.html.erb +0 -0
  50. data/spec/app/views/forums/update.html.erb +0 -0
  51. data/spec/app/views/infos/edit.html.erb +0 -0
  52. data/spec/app/views/infos/show.html.erb +0 -0
  53. data/spec/app/views/interests/index.html.erb +0 -0
  54. data/spec/app/views/interests/show.html.erb +0 -0
  55. data/spec/app/views/owners/edit.html.erb +0 -0
  56. data/spec/app/views/owners/new.html.erb +0 -0
  57. data/spec/app/views/owners/show.html.erb +0 -0
  58. data/spec/app/views/tags/index.html.erb +0 -0
  59. data/spec/app/views/tags/new.html.erb +0 -0
  60. data/spec/app/views/tags/show.html.erb +0 -0
  61. data/spec/app/views/users/edit.html.erb +0 -0
  62. data/spec/app/views/users/index.html.erb +0 -0
  63. data/spec/app/views/users/show.html.erb +0 -0
  64. data/spec/app.rb +315 -0
  65. data/spec/controllers/accounts_controller_spec.rb +77 -0
  66. data/spec/controllers/addresses_controller_spec.rb +346 -0
  67. data/spec/controllers/admin_forums_controller_spec.rb +638 -0
  68. data/spec/controllers/comments_controller_spec.rb +380 -0
  69. data/spec/controllers/comments_controller_with_models_spec.rb +202 -0
  70. data/spec/controllers/forum_posts_controller_spec.rb +426 -0
  71. data/spec/controllers/forums_controller_spec.rb +694 -0
  72. data/spec/controllers/infos_controller_spec.rb +71 -0
  73. data/spec/controllers/interests_controller_via_forum_spec.rb +80 -0
  74. data/spec/controllers/interests_controller_via_user_spec.rb +114 -0
  75. data/spec/controllers/owners_controller_spec.rb +277 -0
  76. data/spec/controllers/resource_saved_spec.rb +47 -0
  77. data/spec/controllers/resource_service_in_forums_controller_spec.rb +37 -0
  78. data/spec/controllers/resource_service_in_infos_controller_spec.rb +36 -0
  79. data/spec/controllers/resource_service_in_interests_controller_via_forum_spec.rb +51 -0
  80. data/spec/controllers/tags_controller_spec.rb +83 -0
  81. data/spec/controllers/tags_controller_via_account_info_spec.rb +131 -0
  82. data/spec/controllers/tags_controller_via_forum_post_comment_spec.rb +144 -0
  83. data/spec/controllers/tags_controller_via_forum_post_spec.rb +133 -0
  84. data/spec/controllers/tags_controller_via_forum_spec.rb +173 -0
  85. data/spec/controllers/tags_controller_via_user_address_spec.rb +130 -0
  86. data/spec/controllers/users_controller_spec.rb +248 -0
  87. data/spec/lib/action_view_helper_spec.rb +143 -0
  88. data/spec/lib/bug_0001_spec.rb +22 -0
  89. data/spec/lib/include_actions_spec.rb +35 -0
  90. data/spec/lib/load_enclosing_resources_spec.rb +245 -0
  91. data/spec/lib/request_path_introspection_spec.rb +130 -0
  92. data/spec/lib/resource_methods_spec.rb +204 -0
  93. data/spec/lib/resources_controller_spec.rb +57 -0
  94. data/spec/models/comment_saved_spec.rb +24 -0
  95. data/spec/rspec_generator_task.rb +105 -0
  96. data/spec/spec_helper.rb +17 -0
  97. data/spec/verify_rcov.rb +52 -0
  98. metadata +193 -0
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe InterestsController do
4
+ describe "resource_service in InterestsController via Forum" do
5
+
6
+ before(:each) do
7
+ @forum = Forum.create
8
+ @interest = Interest.create :interested_in_id => @forum.id, :interested_in_type => 'Forum'
9
+ @other_forum = Forum.create
10
+ @other_interest = Interest.create :interested_in_id => @other_forum.id, :interested_in_type => 'Forum'
11
+
12
+ get :index, :forum_id => @forum.id
13
+ @resource_service = controller.send :resource_service
14
+ end
15
+
16
+ it "should build new interest with @forum fk and type with new" do
17
+ resource = @resource_service.new
18
+ resource.should be_kind_of(Interest)
19
+ resource.interested_in_id.should == @forum.id
20
+ resource.interested_in_type.should == 'Forum'
21
+ end
22
+
23
+ it "should find @interest with find(@interest.id)" do
24
+ resource = @resource_service.find(@interest.id)
25
+ resource.should == @interest
26
+ end
27
+
28
+ it "should raise RecordNotFound with find(@other_interest.id)" do
29
+ lambda{ @resource_service.find(@other_interest.id) }.should raise_error(ActiveRecord::RecordNotFound)
30
+ end
31
+
32
+ it "should find only interests belonging to @forum with find(:all)" do
33
+ resources = @resource_service.find(:all)
34
+ resources.should be == Interest.find(:all, :conditions => "interested_in_id = #{@forum.id} AND interested_in_type = 'Forum'")
35
+ end
36
+
37
+ it "should destroy the interest with destroy(@interest.id)" do
38
+ lambda { @resource_service.destroy(@interest.id) }.should change(Interest, :count).by(-1)
39
+ lambda { Interest.find(@interest.id) }.should raise_error(ActiveRecord::RecordNotFound)
40
+ end
41
+
42
+ it "should NOT destory the other interest with destroy(@other_interest.id)" do
43
+ lambda { @resource_service.destroy(@other_interest.id) }.should raise_error
44
+ Interest.find(@other_interest.id).should == @other_interest
45
+ end
46
+
47
+ it "should return the destroyed interest with destroy(@interest.id)" do
48
+ @resource_service.destroy(@interest.id).should == @interest
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+
3
+ describe TagsController do
4
+ describe "Routing shortcuts for Tags should map" do
5
+
6
+ before(:each) do
7
+ @tag = mock('Tag')
8
+ @tag.stub!(:to_param).and_return('2')
9
+ Tag.stub!(:find).and_return(@tag)
10
+
11
+ @controller.stub!(:request_path).and_return('/tags/2')
12
+ get :show, :id => "2"
13
+ end
14
+
15
+ it "resources_path to /tags" do
16
+ controller.resources_path.should == '/tags'
17
+ end
18
+
19
+ it "resource_path to /tags/2" do
20
+ controller.resource_path.should == '/tags/2'
21
+ end
22
+
23
+ it "resource_path(9) to /tags/9" do
24
+ controller.resource_path(9).should == '/tags/9'
25
+ end
26
+
27
+ it "edit_resource_path to /tags/2/edit" do
28
+ controller.edit_resource_path.should == '/tags/2/edit'
29
+ end
30
+
31
+ it "edit_resource_path(9) to /tags/9/edit" do
32
+ controller.edit_resource_path(9).should == '/tags/9/edit'
33
+ end
34
+
35
+ it "new_resource_path to /forums/1/tags/new" do
36
+ controller.new_resource_path.should == '/tags/new'
37
+ end
38
+
39
+ it "enclosing_resource_path should raise error" do
40
+ lambda{ controller.enclosing_resource_path }.should raise_error
41
+ end
42
+ end
43
+
44
+ describe "resource_service in TagsController" do
45
+
46
+ before(:each) do
47
+ @resource_service = controller.send :resource_service
48
+ end
49
+
50
+ it ".new should call new on Tag" do
51
+ Tag.should_receive(:new).with(:args => "args")
52
+ resource = @resource_service.new(:args => "args")
53
+ end
54
+
55
+ it ".find should call find on Tag" do
56
+ Tag.should_receive(:find).with(:id)
57
+ resource = @resource_service.find(:id)
58
+ end
59
+ end
60
+
61
+ describe "Requesting /tags/index" do
62
+
63
+ before(:each) do
64
+ @tags = mock('Tags')
65
+ Tag.stub!(:all).and_return(@tags)
66
+ end
67
+
68
+ def do_get
69
+ @controller.stub!(:request_path).and_return('/tags/index')
70
+ get :index
71
+ end
72
+
73
+ it "should find the tags" do
74
+ Tag.should_receive(:all).and_return(@tags)
75
+ do_get
76
+ end
77
+
78
+ it "should assign the tags for the view" do
79
+ do_get
80
+ assigns[:tags].should == @tags
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,131 @@
1
+ require 'spec_helper'
2
+
3
+ module TagsViaAccountInfoHelper
4
+ def setup_mocks
5
+ @current_user = mock('user')
6
+ @current_user.stub!(:id).and_return('1')
7
+ User.stub!(:find).and_return(@current_user)
8
+ @info = mock('info')
9
+ @info.stub!(:id).and_return('3')
10
+ @current_user.stub!(:info).and_return(@info)
11
+ @info_tags = mock('info_tags')
12
+ @info.stub!(:tags).and_return(@info_tags)
13
+ @controller.instance_variable_set('@current_user', @current_user)
14
+ end
15
+ end
16
+
17
+ describe TagsController do
18
+ describe "Routing shortcuts for Tags via account info (/account/info/) should map" do
19
+ include TagsViaAccountInfoHelper
20
+
21
+ before(:each) do
22
+ setup_mocks
23
+ @tag = mock('Tag')
24
+ @tag.stub!(:to_param).and_return('2')
25
+ @info_tags.stub!(:find).and_return(@tag)
26
+
27
+ @controller.stub!(:request_path).and_return('/account/info/tags/2')
28
+ get :show, :id => 2
29
+ end
30
+
31
+ it "resources_path to /account/info/tags" do
32
+ controller.resources_path.should == '/account/info/tags'
33
+ end
34
+
35
+ it "resource_path to /account/info/tags/2" do
36
+ controller.resource_path.should == '/account/info/tags/2'
37
+ end
38
+
39
+ it "resource_path(9) to /account/info/tags/9" do
40
+ controller.resource_path(9).should == '/account/info/tags/9'
41
+ end
42
+
43
+ it "edit_resource_path to /account/info/tags/2/edit" do
44
+ controller.edit_resource_path.should == '/account/info/tags/2/edit'
45
+ end
46
+
47
+ it "edit_resource_path(9) to /account/info/tags/9/edit" do
48
+ controller.edit_resource_path(9).should == '/account/info/tags/9/edit'
49
+ end
50
+
51
+ it "new_resource_path to /account/info/tags/new" do
52
+ controller.new_resource_path.should == '/account/info/tags/new'
53
+ end
54
+
55
+ it "enclosing_resource_path to /account/info" do
56
+ controller.enclosing_resource_path.should == "/account/info"
57
+ end
58
+ end
59
+
60
+ describe "resource_service in TagsController via Account Info" do
61
+ include TagsViaAccountInfoHelper
62
+
63
+ before(:each) do
64
+ @info = Info.create
65
+ @account = User.create :info => @info
66
+ @info.tags << (@tag = Tag.create)
67
+ @other_tag = Tag.create
68
+
69
+ @controller.instance_variable_set('@current_user', @account)
70
+ @controller.stub!(:request_path).and_return('/account/info/tags')
71
+ get :index
72
+ @resource_service = controller.send :resource_service
73
+ end
74
+
75
+ it "should build new tag with @info fk and type with new" do
76
+ resource = @resource_service.new
77
+ resource.should be_kind_of(Tag)
78
+ resource.taggable_id.should == @info.id
79
+ resource.taggable_type.should == 'Info'
80
+ end
81
+
82
+ it "should find @tag with find(@tag.id)" do
83
+ resource = @resource_service.find(@tag.id)
84
+ resource.should == @tag
85
+ end
86
+
87
+ it "should raise RecordNotFound with find(@other_tag.id)" do
88
+ lambda{ @resource_service.find(@other_tag.id) }.should raise_error(ActiveRecord::RecordNotFound)
89
+ end
90
+
91
+ it "should find only tags belonging to @info with find(:all)" do
92
+ resources = @resource_service.find(:all)
93
+ resources.should be == Tag.find(:all, :conditions => "taggable_id = #{@info.id} AND taggable_type = 'Info'")
94
+ end
95
+ end
96
+
97
+ describe "Requesting /forums/1/tags using GET" do
98
+ include TagsViaAccountInfoHelper
99
+
100
+ before(:each) do
101
+ setup_mocks
102
+ @tags = mock('Tags')
103
+ @info_tags.stub!(:all).and_return(@tags)
104
+ end
105
+
106
+ def do_get
107
+ @controller.stub!(:request_path).and_return('/account/info/tags')
108
+ get :index
109
+ end
110
+
111
+ it "should find the account as current_user" do
112
+ do_get
113
+ assigns['account'].should == @current_user
114
+ end
115
+
116
+ it "should get info from current_user" do
117
+ @current_user.should_receive(:info).and_return(@info)
118
+ do_get
119
+ end
120
+
121
+ it "should get tags assoc from info" do
122
+ @info.should_receive(:tags).and_return(@info_tags)
123
+ do_get
124
+ end
125
+
126
+ it "should get tags from tags assoc" do
127
+ @info_tags.should_receive(:all).and_return(@tags)
128
+ do_get
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,144 @@
1
+ require 'spec_helper'
2
+
3
+ module TagsViaForumPostCommentSpecHelper
4
+ def setup_mocks
5
+ @forum = mock('Forum')
6
+ Forum.stub!(:find).and_return(@forum)
7
+ @forum.stub!(:to_param).and_return('1')
8
+ @forum_posts = mock('forum_posts assoc')
9
+ @forum.stub!(:posts).and_return(@forum_posts)
10
+
11
+ @post = mock('Post')
12
+ @forum_posts.stub!(:find).and_return(@post)
13
+ @post.stub!(:to_param).and_return('2')
14
+ @post_comments = mock('post_comments assoc')
15
+ @post.stub!(:comments).and_return(@post_comments)
16
+
17
+ @comment = mock('Comment')
18
+ @post_comments.stub!(:find).and_return(@comment)
19
+ @comment.stub!(:to_param).and_return('3')
20
+ @comment_tags = mock('comment_tags assoc')
21
+ @comment.stub!(:tags).and_return(@comment_tags)
22
+ end
23
+ end
24
+
25
+ describe TagsController do
26
+ describe "Routing shortcuts for Tags via Forum, Post and Comment (forums/1/posts/2/comments/3tags/4) should map" do
27
+ include TagsViaForumPostCommentSpecHelper
28
+
29
+ before(:each) do
30
+ setup_mocks
31
+ @tag = mock('Tag')
32
+ @tag.stub!(:to_param).and_return('4')
33
+ @comment_tags.stub!(:find).and_return(@tag)
34
+
35
+ get :show, :forum_id => "1", :post_id => "2", :comment_id => '3', :id => "4"
36
+ end
37
+
38
+ it "resources_path to /forums/1/posts/2/comments/3/tags" do
39
+ controller.resources_path.should == '/forums/1/posts/2/comments/3/tags'
40
+ end
41
+
42
+ it "resource_path to /forums/1/posts/2/comments/3/tags/4" do
43
+ controller.resource_path.should == '/forums/1/posts/2/comments/3/tags/4'
44
+ end
45
+
46
+ it "resource_path(9) to /forums/1/posts/2/comments/3/tags/9" do
47
+ controller.resource_path(9).should == '/forums/1/posts/2/comments/3/tags/9'
48
+ end
49
+
50
+ it "edit_resource_path to /forums/1/posts/2/comments/3/tags/4/edit" do
51
+ controller.edit_resource_path.should == '/forums/1/posts/2/comments/3/tags/4/edit'
52
+ end
53
+
54
+ it "edit_resource_path(9) to /forums/1/posts/2/comments/3/tags/9/edit" do
55
+ controller.edit_resource_path(9).should == '/forums/1/posts/2/comments/3/tags/9/edit'
56
+ end
57
+
58
+ it "new_resource_path to /forums/1/posts/2/comments/3/tags/new" do
59
+ controller.new_resource_path.should == '/forums/1/posts/2/comments/3/tags/new'
60
+ end
61
+
62
+ it "enclosing_resource_path to /forums/1/posts/2/comments/3" do
63
+ controller.enclosing_resource_path.should == "/forums/1/posts/2/comments/3"
64
+ end
65
+ end
66
+
67
+ describe "resource_service in TagsController via Forum, Post and Comment" do
68
+
69
+ before(:each) do
70
+ @forum = Forum.create
71
+ @post = Post.create :forum_id => @forum.id
72
+ @comment = Comment.create :post_id => @post.id, :user => User.create!
73
+ @tag = Tag.create :taggable_id => @comment.id, :taggable_type => 'Comment'
74
+ @other_comment = Comment.create :post_id => @forum.id
75
+ @other_tag = Tag.create :taggable_id => @other_comment.id, :taggable_type => 'Comment'
76
+
77
+ get :index, :forum_id => @forum.id, :post_id => @post.id, :comment_id => @comment.id
78
+ @resource_service = controller.send :resource_service
79
+ end
80
+
81
+ it "should build new tag with @comment fk and type with new" do
82
+ resource = @resource_service.new
83
+ resource.should be_kind_of(Tag)
84
+ resource.taggable_id.should == @comment.id
85
+ resource.taggable_type.should == 'Comment'
86
+ end
87
+
88
+ it "should find @tag with find(@tag.id)" do
89
+ resource = @resource_service.find(@tag.id)
90
+ resource.should == @tag
91
+ end
92
+
93
+ it "should raise RecordNotFound with find(@other_tag.id)" do
94
+ lambda{ @resource_service.find(@other_tag.id) }.should raise_error(ActiveRecord::RecordNotFound)
95
+ end
96
+
97
+ it "should find only tags belonging to @post with find(:all)" do
98
+ resources = @resource_service.find(:all)
99
+ resources.should be == Tag.find(:all, :conditions => "taggable_id = #{@comment.id} AND taggable_type = 'Comment'")
100
+ end
101
+ end
102
+
103
+ describe "Requesting /forums/1/posts/2/comment/3/tags using GET" do
104
+ include TagsViaForumPostCommentSpecHelper
105
+
106
+ before(:each) do
107
+ setup_mocks
108
+ @tags = mock('Tags')
109
+ @comment_tags.stub!(:all).and_return(@tags)
110
+ end
111
+
112
+ def do_get
113
+ get :index, :forum_id => '1', :post_id => '2', :comment_id => '3'
114
+ end
115
+
116
+ it "should find the forum" do
117
+ Forum.should_receive(:find).with('1').and_return(@forum)
118
+ do_get
119
+ end
120
+
121
+ it "should find the post" do
122
+ @forum_posts.should_receive(:find).with('2').and_return(@post)
123
+ do_get
124
+ end
125
+
126
+ it "should find the comment" do
127
+ @post_comments.should_receive(:find).with('3').and_return(@comment)
128
+ do_get
129
+ end
130
+
131
+ it "should assign the found forum, post, and comment for the view" do
132
+ do_get
133
+ assigns[:forum].should == @forum
134
+ assigns[:post].should == @post
135
+ assigns[:comment].should == @comment
136
+ end
137
+
138
+ it "should assign the comment_tags association as the tags resource_service" do
139
+ @comment.should_receive(:tags).and_return(@comment_tags)
140
+ do_get
141
+ @controller.resource_service.should == @comment_tags
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,133 @@
1
+ require 'spec_helper'
2
+
3
+ module TagsViaForumPostSpecHelper
4
+ def setup_mocks
5
+ @forum = mock('Forum')
6
+ Forum.stub!(:find).and_return(@forum)
7
+ @forum.stub!(:to_param).and_return('1')
8
+ @forum_posts = mock('forum_posts assoc')
9
+ @forum.stub!(:posts).and_return(@forum_posts)
10
+
11
+ @post = mock('Post')
12
+ @forum_posts.stub!(:find).and_return(@post)
13
+ @post.stub!(:to_param).and_return('2')
14
+ @post_tags = mock('post_tags assoc')
15
+ @post.stub!(:tags).and_return(@post_tags)
16
+ end
17
+ end
18
+
19
+ describe TagsController do
20
+ describe "Routing shortcuts for Tags via Forum and Post (forums/1/posts/2/tags/3) should map" do
21
+ include TagsViaForumPostSpecHelper
22
+
23
+ before(:each) do
24
+ setup_mocks
25
+ @tag = mock('Tag')
26
+ @tag.stub!(:to_param).and_return('3')
27
+ @post_tags.stub!(:find).and_return(@tag)
28
+
29
+ @controller.stub!(:request_path).and_return('/forums/1/posts/1/tags/3')
30
+ get :show, :forum_id => "1", :post_id => "2", :id => "3"
31
+ end
32
+
33
+ it "resources_path to /forums/1/posts/2/tags" do
34
+ controller.resources_path.should == '/forums/1/posts/2/tags'
35
+ end
36
+
37
+ it "resource_path to /forums/1/posts/2/tags/3" do
38
+ controller.resource_path.should == '/forums/1/posts/2/tags/3'
39
+ end
40
+
41
+ it "resource_path(9) to /forums/1/posts/2/tags/9" do
42
+ controller.resource_path(9).should == '/forums/1/posts/2/tags/9'
43
+ end
44
+
45
+ it "edit_resource_path to /forums/1/posts/2/tags/3/edit" do
46
+ controller.edit_resource_path.should == '/forums/1/posts/2/tags/3/edit'
47
+ end
48
+
49
+ it "edit_resource_path(9) to /forums/1/posts/2/tags/9/edit" do
50
+ controller.edit_resource_path(9).should == '/forums/1/posts/2/tags/9/edit'
51
+ end
52
+
53
+ it "new_resource_path to /forums/1/posts/2/tags/new" do
54
+ controller.new_resource_path.should == '/forums/1/posts/2/tags/new'
55
+ end
56
+
57
+ it "enclosing_resource_path to /forums/1/posts/2" do
58
+ controller.enclosing_resource_path.should == "/forums/1/posts/2"
59
+ end
60
+ end
61
+
62
+ describe "resource_service in TagsController via Forum and Post" do
63
+
64
+ before(:each) do
65
+ @forum = Forum.create
66
+ @post = Post.create :forum_id => @forum.id
67
+ @tag = Tag.create :taggable_id => @post.id, :taggable_type => 'Post'
68
+ @other_post = Post.create :forum_id => @forum.id
69
+ @other_tag = Tag.create :taggable_id => @other_post.id, :taggable_type => 'Post'
70
+
71
+ @controller.stub!(:request_path).and_return("/forums/:id/posts/:id/tags")
72
+ get :index, :forum_id => @forum.id, :post_id => @post.id
73
+ @resource_service = controller.send :resource_service
74
+ end
75
+
76
+ it "should build new tag with @post fk and type with new" do
77
+ resource = @resource_service.new
78
+ resource.should be_kind_of(Tag)
79
+ resource.taggable_id.should == @post.id
80
+ resource.taggable_type.should == 'Post'
81
+ end
82
+
83
+ it "should find @tag with find(@tag.id)" do
84
+ resource = @resource_service.find(@tag.id)
85
+ resource.should == @tag
86
+ end
87
+
88
+ it "should raise RecordNotFound with find(@other_tag.id)" do
89
+ lambda{ @resource_service.find(@other_tag.id) }.should raise_error(ActiveRecord::RecordNotFound)
90
+ end
91
+
92
+ it "should find only tags belonging to @post with find(:all)" do
93
+ resources = @resource_service.find(:all)
94
+ resources.should be == Tag.find(:all, :conditions => "taggable_id = #{@post.id} AND taggable_type = 'Post'")
95
+ end
96
+ end
97
+
98
+ describe "Requesting /forums/1/posts/2/tags using GET" do
99
+ include TagsViaForumPostSpecHelper
100
+
101
+ before(:each) do
102
+ setup_mocks
103
+ @tags = mock('Tags')
104
+ @post_tags.stub!(:all).and_return(@tags)
105
+ end
106
+
107
+ def do_get
108
+ @controller.stub!(:request_path).and_return("/forums/1/posts/2/tags")
109
+ get :index, :forum_id => '1', :post_id => '2'
110
+ end
111
+
112
+ it "should find the forum" do
113
+ Forum.should_receive(:find).with('1').and_return(@forum)
114
+ do_get
115
+ end
116
+
117
+ it "should find the post" do
118
+ @forum_posts.should_receive(:find).with('2').and_return(@post)
119
+ do_get
120
+ end
121
+
122
+ it "should assign the found post for the view" do
123
+ do_get
124
+ assigns[:post].should == @post
125
+ end
126
+
127
+ it "should assign the post_tags association as the tags resource_service" do
128
+ @post.should_receive(:tags).and_return(@post_tags)
129
+ do_get
130
+ @controller.resource_service.should == @post_tags
131
+ end
132
+ end
133
+ end