features/step_definitions/posts_steps.rb in crowdblog-0.0.1 vs features/step_definitions/posts_steps.rb in crowdblog-0.0.2
- old
+ new
@@ -1,35 +1,128 @@
-Given /^I go to the posts page$/ do
- visit posts_path
+#*****************
+# GIVEN steps
+#-----------------
+Given /^(a|\d+) Post.? from other User exists$/ do |number|
+ number = 1 if number.to_i < 1
+
+ number.times { Fabricate :post, author: Fabricate(:user) }
end
-Given /^I fill "([^"]*)" as the post title$/ do |text|
- fill_in 'Title', with: text
+Given /^(?:|the )Published Post exists$/ do
+ step 'Publisher User exists' unless @current_user
+ step 'Test User exists' unless @current_user
+
+ @published_post = Fabricate :post_published, author: @current_user, publisher: @publisher_user
end
-Given /^I fill "([^"]*)" as the post body$/ do |text|
- fill_in 'Body', with: text
+Given /^(?:|the )Test Post exists$/ do
+ step 'Test User exists' unless @current_user
+
+ @post = Fabricate :post_test, author: @current_user
end
-Then /^the post "([^"]*)" should be authored by current user$/ do |post_title|
- post = Crowdblog::Post.find_by_title(post_title)
- post.author.should == @current_user
+
+#*****************
+# WHEN steps
+#-----------------
+When /^(?:|I )delete the Test Post$/ do
+ post = page.find('#posts table tr', text: 'This is a Test Post')
+
+ post.click_link 'Delete'
+ step 'confirm the popup dialog'
end
-Then /^the post "([^"]*)" should have "([^"]*)" as its permalink$/ do |post_title, permalink|
- post = Crowdblog::Post.find_by_title(post_title)
- post.permalink.should == permalink
+When /^(?:|I )Draft a published Post$/ do
+ post = page.find('#posts table tr', text: 'This is a Published Post')
+
+ post.click_link 'Publish' # button should be 'Draft' ?
end
-Then /^the post titled "([^"]*)" is marked as published$/ do |post_title|
- @current_post = Crowdblog::Post.find_by_title(post_title)
- @current_post.should be_published
+When /^(?:|I )edit the Test Post$/ do
+ fill_in 'Title', with: 'I just edited this Post'
+ fill_in 'Body', with: 'OMG, I changed the body of this post!'
+ click_button 'Save'
end
-Then /^current user is set as its publisher$/ do
- @current_post.publisher.should == @current_user
+When /^(?:|I )Publish a drafted Post$/ do
+ post = page.find('#posts table tr', text: 'This is a Test Post')
+
+ post.click_link 'Publish'
end
-Then /^the post titled "([^"]*)" is marked as drafted$/ do |post_title|
- @current_post = Crowdblog::Post.find_by_title(post_title)
- @current_post.should be_drafted
+When /^(?:|I )write a Post$/ do
+ fill_in 'Title', with: 'A Great Post Title'
+ fill_in 'Body', with: 'I just wrote a loooooooong Post'
+ click_button 'Save'
+end
+
+
+#*****************
+# THEN steps
+#-----------------
+Then /^(?:|I )should not see the Test Post$/ do
+ posts = page.find('#posts table')
+
+ posts.should_not have_content 'This is a Test Post'
+end
+
+Then /^(?:|I )should only see my Posts$/ do
+ posts = page.find('#posts table')
+
+ posts.should have_content 'This is a Test Post'
+ posts.should_not have_content 'Random Post title'
+end
+
+Then /^(?:|I )should see my New Post$/ do
+ posts = page.find('#posts table')
+
+ posts.should have_content 'A Great Post Title' # Post Title
+ posts.should have_content 'test@crowdint.com' # Post Author
+
+ post = Crowdblog::Post.find_by_title('A Great Post Title')
+ post.reload.author.should == @current_user
+ post.permalink.should == 'a-great-post-title'
+end
+
+Then /^(?:|I )should see Posts for all Users$/ do
+ posts = page.find('#posts table')
+
+ posts.should have_content 'This is a Test Post'
+ posts.should have_content 'Random Post title'
+end
+
+Then /^(?:|I )should see the Edit Post page$/ do
+ page.should have_content 'Edit Post'
+
+ step 'should see the Post form'
+end
+
+Then /^(?:|I )should see the New Post page$/ do
+ page.should have_content 'New Post'
+
+ step 'should see the Post form'
+end
+
+Then /^(?:|I )should see the Post as Drafted$/ do
+ @post.reload.should be_drafted
+end
+
+Then /^(?:|I )should see the Post as Published$/ do
+ @post.reload.should be_published # Post is published
+ @post.publisher.should == @current_user # Post published by Publisher
+end
+
+Then /^(?:|I )should see the Post form$/ do
+ form = page.find('.container form')
+
+ form.should have_content 'Title'
+ form.should have_content 'Body'
+ form.should have_content 'Markdown syntax'
+ form.should have_content 'Save'
+ form.should have_content 'Cancel'
+end
+
+Then /^(?:|I )should see the Test Post changed$/ do
+ posts = page.find('#posts table')
+
+ posts.should have_content 'I just edited this Post'
end