rc_rails 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/CHANGELOG +355 -0
- data/Gemfile +5 -0
- data/Gemfile.lock.development +117 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +71 -0
- data/Rakefile +33 -0
- data/Todo.txt +1 -0
- data/lib/rc_rails.rb +9 -0
- data/lib/resources_controller/actions.rb +147 -0
- data/lib/resources_controller/active_record/saved.rb +15 -0
- data/lib/resources_controller/helper.rb +123 -0
- data/lib/resources_controller/include_actions.rb +37 -0
- data/lib/resources_controller/named_route_helper.rb +154 -0
- data/lib/resources_controller/railtie.rb +14 -0
- data/lib/resources_controller/request_path_introspection.rb +83 -0
- data/lib/resources_controller/resource_methods.rb +32 -0
- data/lib/resources_controller/singleton_actions.rb +21 -0
- data/lib/resources_controller/specification.rb +119 -0
- data/lib/resources_controller/version.rb +3 -0
- data/lib/resources_controller.rb +849 -0
- data/resources_controller.gemspec +29 -0
- data/spec/app/database.yml +5 -0
- data/spec/app/views/accounts/show.html.erb +0 -0
- data/spec/app/views/addresses/edit.html.erb +0 -0
- data/spec/app/views/addresses/index.html.erb +0 -0
- data/spec/app/views/addresses/new.html.erb +0 -0
- data/spec/app/views/addresses/show.html.erb +0 -0
- data/spec/app/views/admin/forums/create.html.erb +0 -0
- data/spec/app/views/admin/forums/destroy.html.erb +0 -0
- data/spec/app/views/admin/forums/edit.html.erb +0 -0
- data/spec/app/views/admin/forums/index.html.erb +0 -0
- data/spec/app/views/admin/forums/new.html.erb +0 -0
- data/spec/app/views/admin/forums/show.html.erb +0 -0
- data/spec/app/views/admin/forums/update.html.erb +0 -0
- data/spec/app/views/comments/edit.html.erb +0 -0
- data/spec/app/views/comments/index.html.erb +0 -0
- data/spec/app/views/comments/new.html.erb +0 -0
- data/spec/app/views/comments/show.html.erb +0 -0
- data/spec/app/views/forum_posts/edit.html.erb +0 -0
- data/spec/app/views/forum_posts/index.html.erb +0 -0
- data/spec/app/views/forum_posts/new.html.erb +0 -0
- data/spec/app/views/forum_posts/show.html.erb +0 -0
- data/spec/app/views/forums/create.html.erb +0 -0
- data/spec/app/views/forums/destroy.html.erb +0 -0
- data/spec/app/views/forums/edit.html.erb +0 -0
- data/spec/app/views/forums/index.html.erb +0 -0
- data/spec/app/views/forums/new.html.erb +0 -0
- data/spec/app/views/forums/show.html.erb +0 -0
- data/spec/app/views/forums/update.html.erb +0 -0
- data/spec/app/views/infos/edit.html.erb +0 -0
- data/spec/app/views/infos/show.html.erb +0 -0
- data/spec/app/views/interests/index.html.erb +0 -0
- data/spec/app/views/interests/show.html.erb +0 -0
- data/spec/app/views/owners/edit.html.erb +0 -0
- data/spec/app/views/owners/new.html.erb +0 -0
- data/spec/app/views/owners/show.html.erb +0 -0
- data/spec/app/views/tags/index.html.erb +0 -0
- data/spec/app/views/tags/new.html.erb +0 -0
- data/spec/app/views/tags/show.html.erb +0 -0
- data/spec/app/views/users/edit.html.erb +0 -0
- data/spec/app/views/users/index.html.erb +0 -0
- data/spec/app/views/users/show.html.erb +0 -0
- data/spec/app.rb +315 -0
- data/spec/controllers/accounts_controller_spec.rb +77 -0
- data/spec/controllers/addresses_controller_spec.rb +346 -0
- data/spec/controllers/admin_forums_controller_spec.rb +638 -0
- data/spec/controllers/comments_controller_spec.rb +380 -0
- data/spec/controllers/comments_controller_with_models_spec.rb +202 -0
- data/spec/controllers/forum_posts_controller_spec.rb +426 -0
- data/spec/controllers/forums_controller_spec.rb +694 -0
- data/spec/controllers/infos_controller_spec.rb +71 -0
- data/spec/controllers/interests_controller_via_forum_spec.rb +80 -0
- data/spec/controllers/interests_controller_via_user_spec.rb +114 -0
- data/spec/controllers/owners_controller_spec.rb +277 -0
- data/spec/controllers/resource_saved_spec.rb +47 -0
- data/spec/controllers/resource_service_in_forums_controller_spec.rb +37 -0
- data/spec/controllers/resource_service_in_infos_controller_spec.rb +36 -0
- data/spec/controllers/resource_service_in_interests_controller_via_forum_spec.rb +51 -0
- data/spec/controllers/tags_controller_spec.rb +83 -0
- data/spec/controllers/tags_controller_via_account_info_spec.rb +131 -0
- data/spec/controllers/tags_controller_via_forum_post_comment_spec.rb +144 -0
- data/spec/controllers/tags_controller_via_forum_post_spec.rb +133 -0
- data/spec/controllers/tags_controller_via_forum_spec.rb +173 -0
- data/spec/controllers/tags_controller_via_user_address_spec.rb +130 -0
- data/spec/controllers/users_controller_spec.rb +248 -0
- data/spec/lib/action_view_helper_spec.rb +143 -0
- data/spec/lib/bug_0001_spec.rb +22 -0
- data/spec/lib/include_actions_spec.rb +35 -0
- data/spec/lib/load_enclosing_resources_spec.rb +245 -0
- data/spec/lib/request_path_introspection_spec.rb +130 -0
- data/spec/lib/resource_methods_spec.rb +204 -0
- data/spec/lib/resources_controller_spec.rb +57 -0
- data/spec/models/comment_saved_spec.rb +24 -0
- data/spec/rspec_generator_task.rb +105 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/verify_rcov.rb +52 -0
- metadata +193 -0
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module InfosControllerSpecHelper
|
4
|
+
def setup_mocks
|
5
|
+
@current_user = mock('user')
|
6
|
+
@current_user.stub!(:id).and_return('1')
|
7
|
+
@controller.stub!(:current_user).and_return(@current_user)
|
8
|
+
@info = mock('info')
|
9
|
+
@info.stub!(:id).and_return('3')
|
10
|
+
@current_user.stub!(:info).and_return(@info)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe InfosController do
|
15
|
+
describe "Routing shortcuts for Infos should map" do
|
16
|
+
include InfosControllerSpecHelper
|
17
|
+
|
18
|
+
before(:each) do
|
19
|
+
setup_mocks
|
20
|
+
get :show
|
21
|
+
end
|
22
|
+
|
23
|
+
it "resource_path to /account/info" do
|
24
|
+
controller.resource_path.should == '/account/info'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "resource_tags_path to /account/info/tags" do
|
28
|
+
controller.resource_tags_path.should == "/account/info/tags"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe InfosController, " (its actions)" do
|
33
|
+
include InfosControllerSpecHelper
|
34
|
+
|
35
|
+
before do
|
36
|
+
setup_mocks
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should not have ['new', 'index', 'destroy', 'create'] in action_methods" do
|
40
|
+
(@controller.class.send(:action_methods) & Set.new(['new', 'index', 'destroy', 'create'])).should be_empty
|
41
|
+
end
|
42
|
+
|
43
|
+
it "GET /account/info should be successful" do
|
44
|
+
get :show
|
45
|
+
response.should be_success
|
46
|
+
end
|
47
|
+
|
48
|
+
it "GET /account/info/edit should be successful" do
|
49
|
+
get :edit
|
50
|
+
response.should be_success
|
51
|
+
end
|
52
|
+
|
53
|
+
it "PUT /account/info should be successful" do
|
54
|
+
@info.stub!(:update_attributes).and_return(true)
|
55
|
+
put :update
|
56
|
+
response.should be_redirect
|
57
|
+
end
|
58
|
+
|
59
|
+
it "GET /account/info/new should raise ActionNotFound" do
|
60
|
+
lambda { get :new }.should raise_error(::AbstractController::ActionNotFound)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "POST /account/info should raise ActionNotFound" do
|
64
|
+
lambda { post :create }.should raise_error(::AbstractController::ActionNotFound)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "DELETE /account/info/new should raise ActionNotFound" do
|
68
|
+
lambda { delete :destroy }.should raise_error(::AbstractController::ActionNotFound)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module InterestsViaForumSpecHelper
|
4
|
+
def setup_mocks
|
5
|
+
@forum = mock('Forum')
|
6
|
+
@forum_interests = mock('forum_interests assoc')
|
7
|
+
Forum.stub!(:find).and_return(@forum)
|
8
|
+
@forum.stub!(:interests).and_return(@forum_interests)
|
9
|
+
@forum.stub!(:to_param).and_return('1')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe InterestsController do
|
14
|
+
describe "Routing shortcuts for Interests via Forum (forums/1/interests/2) should map" do
|
15
|
+
include InterestsViaForumSpecHelper
|
16
|
+
|
17
|
+
before(:each) do
|
18
|
+
setup_mocks
|
19
|
+
@interest = mock('Interest')
|
20
|
+
@interest.stub!(:to_param).and_return('2')
|
21
|
+
@forum_interests.stub!(:find).and_return(@interest)
|
22
|
+
|
23
|
+
get :show, :forum_id => "1", :id => "2"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "resources_path to /forums/1/interests" do
|
27
|
+
controller.resources_path.should == '/forums/1/interests'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "resource_path to /forums/1/interests/2" do
|
31
|
+
controller.resource_path.should == '/forums/1/interests/2'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "resource_path(9) to /forums/1/interests/9" do
|
35
|
+
controller.resource_path(9).should == '/forums/1/interests/9'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "edit_resource_path to /forums/1/interests/2/edit" do
|
39
|
+
controller.edit_resource_path.should == '/forums/1/interests/2/edit'
|
40
|
+
end
|
41
|
+
|
42
|
+
it "edit_resource_path(9) to /forums/1/interests/9/edit" do
|
43
|
+
controller.edit_resource_path(9).should == '/forums/1/interests/9/edit'
|
44
|
+
end
|
45
|
+
|
46
|
+
it "new_resource_path to /forums/1/interests/new" do
|
47
|
+
controller.new_resource_path.should == '/forums/1/interests/new'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "Requesting /forums/1/interests using GET" do
|
52
|
+
include InterestsViaForumSpecHelper
|
53
|
+
|
54
|
+
before(:each) do
|
55
|
+
setup_mocks
|
56
|
+
@interests = mock('Interests')
|
57
|
+
@forum_interests.stub!(:all).and_return(@interests)
|
58
|
+
end
|
59
|
+
|
60
|
+
def do_get
|
61
|
+
get :index, :forum_id => '1'
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should find the forum" do
|
65
|
+
Forum.should_receive(:find).with('1').and_return(@forum)
|
66
|
+
do_get
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should assign the found forum as :interested_in for the view" do
|
70
|
+
do_get
|
71
|
+
assigns[:interested_in].should == @forum
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should assign the forum_interests association as the interests resource_service" do
|
75
|
+
@forum.should_receive(:interests).and_return(@forum_interests)
|
76
|
+
do_get
|
77
|
+
@controller.resource_service.should == @forum_interests
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module InterestsViaUserSpecHelper
|
4
|
+
def setup_mocks
|
5
|
+
@user = mock('User')
|
6
|
+
@user_interests = mock('user_interests assoc')
|
7
|
+
User.stub!(:find_by_login).and_return(@user)
|
8
|
+
@user.stub!(:interests).and_return(@user_interests)
|
9
|
+
@user.stub!(:to_param).and_return('dave')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe InterestsController do
|
14
|
+
describe "Routing shortcuts for Interests via User (users/dave/interests/2) should map" do
|
15
|
+
include InterestsViaUserSpecHelper
|
16
|
+
|
17
|
+
before(:each) do
|
18
|
+
setup_mocks
|
19
|
+
@interest = mock('Interest')
|
20
|
+
@interest.stub!(:to_param).and_return('2')
|
21
|
+
@user_interests.stub!(:find).and_return(@interest)
|
22
|
+
|
23
|
+
get :show, :user_id => "dave", :id => "2"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "resources_path to /users/dave/interests" do
|
27
|
+
controller.resources_path.should == '/users/dave/interests'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "resource_path to /users/dave/interests/2" do
|
31
|
+
controller.resource_path.should == '/users/dave/interests/2'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "resource_path(9) to /users/dave/interests/9" do
|
35
|
+
controller.resource_path(9).should == '/users/dave/interests/9'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "edit_resource_path to /users/dave/interests/2/edit" do
|
39
|
+
controller.edit_resource_path.should == '/users/dave/interests/2/edit'
|
40
|
+
end
|
41
|
+
|
42
|
+
it "edit_resource_path(9) to /users/dave/interests/9/edit" do
|
43
|
+
controller.edit_resource_path(9).should == '/users/dave/interests/9/edit'
|
44
|
+
end
|
45
|
+
|
46
|
+
it "new_resource_path to /users/dave/interests/new" do
|
47
|
+
controller.new_resource_path.should == '/users/dave/interests/new'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "resource_service in InterestsController via Forum" do
|
52
|
+
|
53
|
+
before(:each) do
|
54
|
+
@user = User.create :login => 'dave'
|
55
|
+
@interest = Interest.create :interested_in_id => @user.id, :interested_in_type => 'User'
|
56
|
+
@other_user = User.create
|
57
|
+
@other_interest = Interest.create :interested_in_id => @other_user.id, :interested_in_type => 'User'
|
58
|
+
|
59
|
+
get :index, :user_id => @user.login
|
60
|
+
@resource_service = controller.send :resource_service
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should build new interest with @user fk and type with new" do
|
64
|
+
resource = @resource_service.new
|
65
|
+
resource.should be_kind_of(Interest)
|
66
|
+
resource.interested_in_id.should == @user.id
|
67
|
+
resource.interested_in_type.should == 'User'
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should find @interest with find(@interest.id)" do
|
71
|
+
resource = @resource_service.find(@interest.id)
|
72
|
+
resource.should == @interest
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should raise RecordNotFound with find(@other_interest.id)" do
|
76
|
+
lambda{ @resource_service.find(@other_interest.id) }.should raise_error(ActiveRecord::RecordNotFound)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should find only interests belonging to @user with find(:all)" do
|
80
|
+
resources = @resource_service.find(:all)
|
81
|
+
resources.should be == Interest.find(:all, :conditions => "interested_in_id = #{@user.id} AND interested_in_type = 'User'")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "Requesting /users/dave/interests using GET" do
|
86
|
+
include InterestsViaUserSpecHelper
|
87
|
+
|
88
|
+
before(:each) do
|
89
|
+
setup_mocks
|
90
|
+
@interests = mock('Interests')
|
91
|
+
@user_interests.stub!(:all).and_return(@interests)
|
92
|
+
end
|
93
|
+
|
94
|
+
def do_get
|
95
|
+
get :index, :user_id => "dave"
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should find the user" do
|
99
|
+
User.should_receive(:find_by_login).with('dave').and_return(@user)
|
100
|
+
do_get
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should assign the found user as :interested_in for the view" do
|
104
|
+
do_get
|
105
|
+
assigns[:interested_in].should == @user
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should assign the user_interests association as the interests resource_service" do
|
109
|
+
@user.should_receive(:interests).and_return(@user_interests)
|
110
|
+
do_get
|
111
|
+
@controller.resource_service.should == @user_interests
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,277 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module OwnersControllerSpecHelper
|
4
|
+
def setup_mocks
|
5
|
+
@forum = mock('forum')
|
6
|
+
@forum.stub!(:id).and_return(2)
|
7
|
+
@forum.stub!(:to_param).and_return('2')
|
8
|
+
Forum.stub!(:find).and_return(@forum)
|
9
|
+
@owner = mock_model(User)
|
10
|
+
@forum.stub!(:owner).and_return(@owner)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe OwnersController do
|
15
|
+
describe "Routing shortcuts for ForumOwner should map" do
|
16
|
+
include OwnersControllerSpecHelper
|
17
|
+
|
18
|
+
before(:each) do
|
19
|
+
setup_mocks
|
20
|
+
get :show, :forum_id => "2"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "resource_path to /forums/2/owner" do
|
24
|
+
controller.resource_path.should == '/forums/2/owner'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "resource_path(:foo => 'bar') to /forums/2/owner?foo=bar" do
|
28
|
+
controller.resource_path(:foo => 'bar').should == '/forums/2/owner?foo=bar'
|
29
|
+
end
|
30
|
+
|
31
|
+
it "edit_resource_path to /forums/2/owner/edit" do
|
32
|
+
controller.edit_resource_path.should == '/forums/2/owner/edit'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "new_resource_path to /forums/2/owner/new" do
|
36
|
+
controller.new_resource_path.should == '/forums/2/owner/new'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "resource_posts_path to /forums/2/owner/posts" do
|
40
|
+
controller.resource_posts_path.should == "/forums/2/owner/posts"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "resource_posts_path(:foo => 'bar') to /forums/2/owner/posts?foo=bar" do
|
44
|
+
controller.resource_posts_path(:foo => 'bar').should == '/forums/2/owner/posts?foo=bar'
|
45
|
+
end
|
46
|
+
|
47
|
+
it "resource_post_path(5) to /forums/2/owner/posts/5" do
|
48
|
+
controller.resource_post_path(5).should == "/forums/2/owner/posts/5"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "enclosing_resource_path to /forums/2" do
|
52
|
+
controller.enclosing_resource_path.should == "/forums/2"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe OwnersController, "#resource_service" do
|
57
|
+
include OwnersControllerSpecHelper
|
58
|
+
|
59
|
+
before(:each) do
|
60
|
+
setup_mocks
|
61
|
+
get :show, :forum_id => "2"
|
62
|
+
@resource_service = controller.send :resource_service
|
63
|
+
end
|
64
|
+
|
65
|
+
it ".new should call :build_owner on @forum" do
|
66
|
+
@forum.should_receive(:build_owner).with(:args => 'args')
|
67
|
+
@resource_service.new :args => 'args'
|
68
|
+
end
|
69
|
+
|
70
|
+
it ".find should call :owner on @forum" do
|
71
|
+
@forum.should_receive(:owner)
|
72
|
+
@resource_service.find
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "Requesting /forums/2/owner using GET" do
|
77
|
+
include OwnersControllerSpecHelper
|
78
|
+
|
79
|
+
before(:each) do
|
80
|
+
setup_mocks
|
81
|
+
end
|
82
|
+
|
83
|
+
def do_get
|
84
|
+
get :show, :forum_id => "2"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should be successful" do
|
88
|
+
do_get
|
89
|
+
response.should be_success
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should render show.rhtml" do
|
93
|
+
do_get
|
94
|
+
response.should render_template(:show)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should find the forum requested" do
|
98
|
+
Forum.should_receive(:find).with("2").and_return(@forum)
|
99
|
+
do_get
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should assign the found forum for the view" do
|
103
|
+
do_get
|
104
|
+
assigns[:forum].should == @forum
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should find the owner from forum.owner" do
|
108
|
+
@forum.should_receive(:owner).and_return(@owner)
|
109
|
+
do_get
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should assign the found owner for the view" do
|
113
|
+
do_get
|
114
|
+
assigns[:owner].should == @owner
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "Requesting /forums/2/owner/new using GET" do
|
119
|
+
include OwnersControllerSpecHelper
|
120
|
+
|
121
|
+
before(:each) do
|
122
|
+
setup_mocks
|
123
|
+
@forum.stub!(:build_owner).and_return(@owner)
|
124
|
+
end
|
125
|
+
|
126
|
+
def do_get
|
127
|
+
get :new, :forum_id => "2"
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should be successful" do
|
131
|
+
do_get
|
132
|
+
response.should be_success
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should render new.rhtml" do
|
136
|
+
do_get
|
137
|
+
response.should render_template(:new)
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should build a new owner" do
|
141
|
+
@forum.should_receive(:build_owner).and_return(@owner)
|
142
|
+
do_get
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "Requesting /forums/2/owner/edit using GET" do
|
147
|
+
include OwnersControllerSpecHelper
|
148
|
+
|
149
|
+
before(:each) do
|
150
|
+
setup_mocks
|
151
|
+
end
|
152
|
+
|
153
|
+
def do_get
|
154
|
+
get :edit, :forum_id => "2"
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should be successful" do
|
158
|
+
do_get
|
159
|
+
response.should be_success
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should render edit.rhtml" do
|
163
|
+
do_get
|
164
|
+
response.should render_template(:edit)
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should find the owner from forum.owner" do
|
168
|
+
@forum.should_receive(:owner).and_return(@owner)
|
169
|
+
do_get
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe "Requesting /forums/2/owner using POST" do
|
174
|
+
include OwnersControllerSpecHelper
|
175
|
+
|
176
|
+
before(:each) do
|
177
|
+
setup_mocks
|
178
|
+
@owner.stub!(:save).and_return(true)
|
179
|
+
@owner.stub!(:to_param).and_return("1")
|
180
|
+
@forum.stub!(:build_owner).and_return(@owner)
|
181
|
+
end
|
182
|
+
|
183
|
+
def do_post
|
184
|
+
post :create, :forum_id => 2, :owner => {:name => 'Fred'}
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should build a new owner" do
|
188
|
+
@forum.should_receive(:build_owner).with({'name' => 'Fred'}).and_return(@owner)
|
189
|
+
do_post
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should set the flash notice" do
|
193
|
+
do_post
|
194
|
+
flash[:notice].should == "Owner was successfully created."
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should redirect to the new owner" do
|
198
|
+
do_post
|
199
|
+
response.should be_redirect
|
200
|
+
response.redirect_url.should == "http://test.host/forums/2/owner"
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should render new when post unsuccesful" do
|
204
|
+
@owner.stub!(:save).and_return(false)
|
205
|
+
do_post
|
206
|
+
response.should render_template('new')
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
|
211
|
+
describe "Requesting /forums/2/owner using PUT" do
|
212
|
+
include OwnersControllerSpecHelper
|
213
|
+
|
214
|
+
before(:each) do
|
215
|
+
setup_mocks
|
216
|
+
@owner.stub!(:update_attributes).and_return(true)
|
217
|
+
end
|
218
|
+
|
219
|
+
def do_update
|
220
|
+
put :update, :forum_id => "2", :owner => {:name => 'Fred'}
|
221
|
+
end
|
222
|
+
|
223
|
+
it "should find the owner from forum.owner" do
|
224
|
+
@forum.should_receive(:owner).and_return(@owner)
|
225
|
+
do_update
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should set the flash notice" do
|
229
|
+
do_update
|
230
|
+
flash[:notice].should == "Owner was successfully updated."
|
231
|
+
end
|
232
|
+
|
233
|
+
it "should update the owner" do
|
234
|
+
@owner.should_receive(:update_attributes).with('name' => 'Fred')
|
235
|
+
do_update
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should redirect to the owner" do
|
239
|
+
do_update
|
240
|
+
response.should redirect_to("http://test.host/forums/2/owner")
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
|
245
|
+
describe "Requesting /forums/2/owner using DELETE" do
|
246
|
+
include OwnersControllerSpecHelper
|
247
|
+
|
248
|
+
before(:each) do
|
249
|
+
setup_mocks
|
250
|
+
@owner.stub!(:destroy).and_return(@owner)
|
251
|
+
end
|
252
|
+
|
253
|
+
def do_delete
|
254
|
+
delete :destroy, :forum_id => "2"
|
255
|
+
end
|
256
|
+
|
257
|
+
it "should find the owner from forum.owner" do
|
258
|
+
@forum.should_receive(:owner).and_return(@owner)
|
259
|
+
do_delete
|
260
|
+
end
|
261
|
+
|
262
|
+
it "should call destroy on the owner" do
|
263
|
+
@owner.should_receive(:destroy).and_return(@owner)
|
264
|
+
do_delete
|
265
|
+
end
|
266
|
+
|
267
|
+
it "should set the flash notice" do
|
268
|
+
do_delete
|
269
|
+
flash[:notice].should == 'Owner was successfully destroyed.'
|
270
|
+
end
|
271
|
+
|
272
|
+
it "should redirect to forums/2" do
|
273
|
+
do_delete
|
274
|
+
response.should redirect_to("http://test.host/forums/2")
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CommentsController, "#resource_saved" do
|
4
|
+
describe "Comment.new(<invalid attrs>)" do
|
5
|
+
before { @controller.resource = Comment.new }
|
6
|
+
|
7
|
+
it { @controller.should_not be_resource_saved }
|
8
|
+
|
9
|
+
describe ".save" do
|
10
|
+
before { @controller.resource.save }
|
11
|
+
|
12
|
+
it { @controller.should_not be_resource_saved }
|
13
|
+
|
14
|
+
describe "then update_attributes(<valid attrs>)" do
|
15
|
+
before { @controller.resource.update_attributes :user => User.create!, :post => Post.create! }
|
16
|
+
|
17
|
+
it { @controller.should be_resource_saved }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "Comment.find(<id>)" do
|
23
|
+
before do
|
24
|
+
Comment.create! :user => User.create!, :post => Post.create!
|
25
|
+
@controller.resource = Comment.find(:first)
|
26
|
+
end
|
27
|
+
|
28
|
+
it { @controller.should be_resource_saved }
|
29
|
+
|
30
|
+
it ".save should be saved" do
|
31
|
+
@controller.resource.save
|
32
|
+
@controller.should be_resource_saved
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "then update_attributes(<invalid attrs>)" do
|
36
|
+
before { @controller.resource.update_attributes :user => nil }
|
37
|
+
|
38
|
+
it { @controller.should_not be_resource_saved }
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "then update_attributes(<new valid attrs>)" do
|
42
|
+
before { @controller.resource.update_attributes :user => User.create! }
|
43
|
+
|
44
|
+
it { @controller.should be_resource_saved }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ForumsController do
|
4
|
+
describe "resource_service in ForumsController" do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@forum = Forum.create
|
8
|
+
|
9
|
+
get :index
|
10
|
+
@resource_service = controller.send :resource_service
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should build new forum with new" do
|
14
|
+
resource = @resource_service.new
|
15
|
+
resource.should be_kind_of(Forum)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should find @forum with find(@forum.id)" do
|
19
|
+
resource = @resource_service.find(@forum.id)
|
20
|
+
resource.should == @forum
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should find all forums with find(:all)" do
|
24
|
+
resources = @resource_service.find(:all)
|
25
|
+
resources.should == Forum.find(:all)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should destroy the forum with destroy(@forum.id)" do
|
29
|
+
lambda { @resource_service.destroy(@forum.id) }.should change(Forum, :count).by(-1)
|
30
|
+
lambda { Forum.find(@forum.id) }.should raise_error(ActiveRecord::RecordNotFound)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return the destroyed forum with destroy(@forum.id)" do
|
34
|
+
@resource_service.destroy(@forum.id).should == @forum
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe InfosController do
|
4
|
+
describe "resource_service in InfosController via Account(a user)" do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@account = User.create!
|
8
|
+
@info = Info.create! :user_id => @account.id
|
9
|
+
|
10
|
+
@controller.stub!(:current_user).and_return(@account)
|
11
|
+
|
12
|
+
get :show, :resource_path => '/account/info'
|
13
|
+
@resource_service = controller.send :resource_service
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should build new interest on the account" do
|
17
|
+
resource = @resource_service.new
|
18
|
+
resource.should be_kind_of(Info)
|
19
|
+
resource.user_id.should == @account.id
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should find @info with find" do
|
23
|
+
resource = @resource_service.find
|
24
|
+
resource.should == @info
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should destroy the info with destroy" do
|
28
|
+
lambda { @resource_service.destroy }.should change(Info, :count).by(-1)
|
29
|
+
lambda { Info.find(@info.id) }.should raise_error(ActiveRecord::RecordNotFound)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return the destroyed info with destroy" do
|
33
|
+
@resource_service.destroy.should == @info
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|