Skip to content

Commit

Permalink
resources_controller: Added more specs to get coverage to 100%
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.ardes.com/rails_plugins/resources_controller@252 845bbffb-5c18-0410-91b3-f25c072b94c1
  • Loading branch information
ian committed May 10, 2007
1 parent 6dccf6a commit f042826
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,3 +1,5 @@
* Added more specs to get coverage to 100%

* Upgraded to rpsec 0.9, improved Rakefile and specs so that spec:plugins will work

* Removed ApplicationController from spec/app.rb to avoid conflicts with en-
Expand Down
34 changes: 30 additions & 4 deletions SPECDOC
Expand Up @@ -164,8 +164,10 @@ Requesting /forums/2/posts/1/edit using GET
- should assign the found Thing for the view

Requesting /forums/2/posts using POST
- should create a new post
- should redirect to the new post
- should make a new post
- should attempt to save the new post
- should redirect to the new post.save == true
- should render new when post.save == false

Requesting /forums/2/posts/1 using PUT
- should find the post requested
Expand All @@ -185,6 +187,12 @@ Routing shortcuts for ForumPosts (forums/1) should map
- edit_resource_path to /forums/2/edit
- edit_resource_path(9) to /forums/9/edit
- new_resource_path to /forums/new
- resources_url to http://test.host/forums
- resource_url to http://test.host/forums/2
- resource_url(9) to http://test.host/forums/9
- edit_resource_url to http://test.host/forums/2/edit
- edit_resource_url(9) to http://test.host/forums/9/edit
- new_resource_url to http://test.host/forums/new

resource_service in ForumsController
- should build new forum with new
Expand Down Expand Up @@ -359,6 +367,24 @@ Requesting /users/1/addresses/2/tags using GET
- should assign the found address as :taggable for the view
- should assign the address_tags association as the tags resource_service

ActionView with resources_controller Helper
- should forward #resource_name to controller
- should forward #resources_name to controller
- should forward #resource to controller
- should forward #resources to controller
- should forward #resource_url(*resource) to controller
- should forward #edit_resource_url(*resource) to controller
- should forward #resources_url to controller
- should forward #new_resource_url to controller
- should forward #resource_path(*resource) to controller
- should forward #edit_resource_path(*resource) to controller
- should forward #resources_path to controller
- should forward #new_resource_path to controller

A controller's resource_service
- should pass unknown methods to the resource service of the controller
- may be explicitly set with #resource_service=

ResourcesController (route_name, singular_route_name and name_prefix)
- route_name should be the controller_name by default
- singular_route_name should be route_name.singualrize(d)
Expand All @@ -375,6 +401,6 @@ Automatic (route_name, name_prefix) for
- HasAComplexNameController should be ('has_a_complex_name', '')
- EnclosedByFooHasAComplexNameController should be ('has_a_complex_name', 'enclosed_by_foo_')

Finished in 2.23136 seconds
Finished in 2.140308 seconds

254 examples, 0 failures
276 examples, 0 failures
2 changes: 1 addition & 1 deletion lib/ardes/resources_controller.rb
Expand Up @@ -663,7 +663,7 @@ class ResourceService
attr_reader :controller, :service

# When the resource service is created, the default service is either the resource_class (in the case
# where therea re no enclosing resources) or the collection on the last enclosing resource (hwne there are enclosing
# when there are no enclosing resources) or the collection of the last enclosing resource (when there are enclosing
# resources)
def initialize(controller)
@controller = controller
Expand Down
4 changes: 4 additions & 0 deletions spec/app.rb
Expand Up @@ -161,4 +161,8 @@ class TagsController < ActionController::Base
end
end
end

# Install the default route as the lowest priority.
map.connect ':controller/:action/:id.:format'
map.connect ':controller/:action/:id'
end
15 changes: 13 additions & 2 deletions spec/controllers/forum_posts_controller_spec.rb
Expand Up @@ -276,16 +276,27 @@ def do_post
post :create, :post => {:name => 'Post'}, :forum_id => "2"
end

it "should create a new post" do
it "should make a new post" do
@forum_posts.should_receive(:new).with({'name' => 'Post'}).and_return(@post)
do_post
end

it "should redirect to the new post" do
it "should attempt to save the new post" do
@post.should_receive(:save)
do_post
end

it "should redirect to the new post.save == true" do
do_post
response.should be_redirect
response.redirect_url.should == "http://test.host/forums/2/posts/1"
end

it "should render new when post.save == false" do
@post.stub!(:save).and_return(false)
do_post
response.should render_template(:new)
end
end

describe "Requesting /forums/2/posts/1 using PUT" do
Expand Down
24 changes: 24 additions & 0 deletions spec/controllers/forums_controller_spec.rb
Expand Up @@ -34,6 +34,30 @@
it "new_resource_path to /forums/new" do
controller.new_resource_path.should == '/forums/new'
end

it "resources_url to http://test.host/forums" do
controller.resources_url.should == 'http://test.host/forums'
end

it "resource_url to http://test.host/forums/2" do
controller.resource_url.should == 'http://test.host/forums/2'
end

it "resource_url(9) to http://test.host/forums/9" do
controller.resource_url(9).should == 'http://test.host/forums/9'
end

it "edit_resource_url to http://test.host/forums/2/edit" do
controller.edit_resource_url.should == 'http://test.host/forums/2/edit'
end

it "edit_resource_url(9) to http://test.host/forums/9/edit" do
controller.edit_resource_url(9).should == 'http://test.host/forums/9/edit'
end

it "new_resource_url to http://test.host/forums/new" do
controller.new_resource_url.should == 'http://test.host/forums/new'
end
end

describe "resource_service in ForumsController" do
Expand Down
32 changes: 32 additions & 0 deletions spec/specs/action_view_helper_spec.rb
@@ -0,0 +1,32 @@
require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
require File.expand_path(File.join(File.dirname(__FILE__), '../app'))

describe "ActionView with resources_controller Helper" do

before do
@view = mock('View')
@view.extend Ardes::ResourcesController::Helper
@controller = mock('Controller')
@view.stub!(:controller).and_return(@controller)
end

def self.it_should_forward_to_controller(msg, *args)
it "should forward ##{msg}#{args.size > 0 ? "(#{args.join(',')})" : ""} to controller" do
@controller.should_receive(msg).with(*args)
@view.send(msg, *args)
end
end

it_should_forward_to_controller :resource_name
it_should_forward_to_controller :resources_name
it_should_forward_to_controller :resource
it_should_forward_to_controller :resources
it_should_forward_to_controller :resource_url, '*resource'
it_should_forward_to_controller :edit_resource_url, '*resource'
it_should_forward_to_controller :resources_url
it_should_forward_to_controller :new_resource_url
it_should_forward_to_controller :resource_path, '*resource'
it_should_forward_to_controller :edit_resource_path, '*resource'
it_should_forward_to_controller :resources_path
it_should_forward_to_controller :new_resource_path
end
21 changes: 21 additions & 0 deletions spec/specs/resource_service_spec.rb
@@ -0,0 +1,21 @@
require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
require File.expand_path(File.join(File.dirname(__FILE__), '../app'))

describe "A controller's resource_service" do

before do
Forum.stub!(:gday)
@controller = ForumsController.new
@service = @controller.resource_service
end

it 'should pass unknown methods to the resource service of the controller' do
Forum.should_receive(:gday)
@service.gday
end

it 'may be explicitly set with #resource_service=' do
@controller.resource_service = 'foo'
@controller.resource_service.should == 'foo'
end
end

0 comments on commit f042826

Please sign in to comment.