Skip to content

Commit

Permalink
Use more than one fixture for some of the article controller specs.
Browse files Browse the repository at this point in the history
Requires correct sequencing of the updated_at property.
  • Loading branch information
mvz committed Jan 17, 2011
1 parent 696a8ba commit 775f5af
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
25 changes: 15 additions & 10 deletions spec/controllers/articles_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@


describe '#search action' do
before :each do
Factory(:article,
:body => "in markdown format\n\n * we\n * use\n [ok](http://blog.ok.com) to define a link",
:text_filter => Factory(:markdown))
Factory(:article, :body => "xyz")
end

describe 'a valid search' do
before :each do
Factory(:article,
:body => "in markdown format\n\n * we\n * use\n [ok](http://blog.ok.com) to define a link",
:text_filter => Factory(:markdown))
get 'search', :q => 'a'
end

Expand Down Expand Up @@ -73,15 +77,13 @@
end

it 'should render feed rss by search' do
Factory(:article)
get 'search', :q => 'a', :format => 'rss'
response.should be_success
response.should render_template('articles/_rss20_feed')
assert_feedvalidator response.body
end

it 'should render feed atom by search' do
Factory(:article)
get 'search', :q => 'a', :format => 'atom'
response.should be_success
response.should render_template('articles/_atom_feed')
Expand Down Expand Up @@ -133,9 +135,11 @@


it 'archives' do
3.times { Factory(:article) }
get 'archives'
response.should render_template(:archives)
assigns[:articles].should_not be_nil
assigns[:articles].should_not be_empty
end

describe 'index for a month' do
Expand All @@ -151,6 +155,7 @@

it 'should contain some articles' do
assigns[:articles].should_not be_nil
assigns[:articles].should_not be_empty
end
end

Expand Down Expand Up @@ -193,6 +198,11 @@
:created_at => Time.now - 1.day)
Factory.create(:trackback, :article => @article, :published_at => Time.now - 1.day,
:published => true)
Factory.create(:article,
:created_at => '2004-04-01 12:00:00',
:published_at => '2004-04-01 12:00:00',
:updated_at => '2004-04-01 12:00:00')

end

specify "/articles.atom => an atom feed" do
Expand All @@ -211,11 +221,6 @@
end

specify "atom feed for archive should be valid" do
article = Factory.create(:article,
:created_at => '2004-04-01 12:00:00',
:published_at => '2004-04-01 12:00:00',
:updated_at => '2004-04-01 12:00:00')

get 'index', :year => 2004, :month => 4, :format => 'atom'
response.should render_template("_atom_feed")
assert_feedvalidator response.body
Expand Down
7 changes: 7 additions & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
"category_#{n}"
end

basetime = Time.now

Factory.sequence :time do |n|
basetime - n
end

Factory.define :user do |u|
u.login { Factory.next(:user) }
u.email { Factory.next(:user) }
Expand All @@ -40,6 +46,7 @@
a.guid { Factory.next(:guid) }
a.permalink 'a-big-article'
a.published_at '2005-01-01 02:00:00'
a.updated_at { Factory.next(:time) }
a.user { |u| u.association(:user) }
a.allow_comments true
a.published true
Expand Down

0 comments on commit 775f5af

Please sign in to comment.