how a can test this controller using rspec
#home controller
def home
@recents = Article.publisheds.with_authorship.paginate(:page =>
1, :per_page => 10, :total_entries => 10)
@highlight = Article.publisheds.highlight.with_authorship
end
#article model
named_scope :publisheds, lambda { { :conditions => ["published_at
<= ? and status = 'publicado'", Time.now.utc] } }
named_scope :highlight, lambda { { :conditions => ["highlight IS NOT
NULL and highlight <> ''"], :order => "highlight desc, published_at
desc", :limit => 4 } }
named_scope :with_authorship, :include => [:authorships, :authors]
i do this bat dont work:
describe GeneralController do
def mock_article(stubs={})
@mock_article ||= mock_model(Article, stubs)
end
describe "GET index" do
it "should expose article as @articles" do
articles = [mock_article]
Article.should_receive(:publisheds).and_return(articles)
articles.should_receive(:with_authorship).and_return(articles)
articles.should_receive(:paginate).with(:per_page =>
10,:total_entries=>10, :page => 1).and_return(articles)
get :home
assigns[:recents].should == articles
end
end
end
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users