Skip to content

Commit

Permalink
Fix for when should_assign_to tries to check an explicitly false inst…
Browse files Browse the repository at this point in the history
…ance variable [thoughtbot#117]
  • Loading branch information
rmm5t committed Jan 6, 2009
1 parent 0c47c51 commit 30458c5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/shoulda/controller/macros.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def should_assign_to(*names)
test_name << " which is equal to #{opts[:equals]}" if opts[:equals]
should test_name do
assigned_value = assigns(name.to_sym)
assert assigned_value, "The action isn't assigning to @#{name}"
assert_not_nil assigned_value, "The action isn't assigning to @#{name}"
assert_kind_of opts[:class], assigned_value if opts[:class]
if opts[:equals]
instantiate_variables_from_assigns do
Expand Down
7 changes: 4 additions & 3 deletions test/functional/posts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def setup
@response = ActionController::TestResponse.new
@post = Post.find(:first)
end

# autodetects the :controller
should_route :get, '/posts', :action => :index
# explicitly specify :controller
Expand All @@ -24,7 +24,7 @@ def setup
should_route :put, '/posts/1', :action => :update, :id => "1"
should_route :delete, '/posts/1', :action => :destroy, :id => 1
should_route :get, '/posts/new', :action => :new

# Test the nested routes
should_route :get, '/users/5/posts', :action => :index, :user_id => 5
should_route :post, '/users/5/posts', :action => :create, :user_id => 5
Expand Down Expand Up @@ -74,7 +74,7 @@ def setup
should_assign_to :posts
should_not_assign_to :foo, :bar
should_render_page_with_metadata :description => /Posts/, :title => /index/
should_render_page_with_metadata :keywords => "posts"
should_render_page_with_metadata :keywords => "posts"
end

context "viewing posts for a user with rss format" do
Expand All @@ -96,6 +96,7 @@ def setup
setup { get :show, :user_id => users(:first), :id => posts(:first) }
should_render_with_layout 'wide'
should_render_with_layout :wide
should_assign_to :false_flag
end

context "on GET to #new" do
Expand Down
11 changes: 6 additions & 5 deletions test/rails_root/app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class PostsController < ApplicationController
before_filter :ensure_logged_in
before_filter :load_user

def index
@posts = @user.posts

Expand All @@ -19,6 +19,7 @@ def index

def show
@post = @user.posts.find(params[:id])
@false_flag = false

respond_to do |format|
format.html { render :layout => 'wide' }
Expand Down Expand Up @@ -68,17 +69,17 @@ def update
def destroy
@post = @user.posts.find(params[:id])
@post.destroy

flash[:notice] = "Post was removed"

respond_to do |format|
format.html { redirect_to user_posts_url(@post.user) }
format.xml { head :ok }
end
end

private

def load_user
@user = User.find(params[:user_id])
end
Expand Down

0 comments on commit 30458c5

Please sign in to comment.