Permalink
Browse files

tested article publish/unpublish feature and article previewing feature

  • Loading branch information...
raw1z committed Feb 9, 2012
1 parent 5cb4128 commit a33478e9da005b6ef3256e8b50cff34532c21763
View
@@ -7,4 +7,5 @@ spec/dummy/db/*.sqlite3
spec/dummy/log/*.log
spec/dummy/tmp/
spec/dummy/.sass-cache
-vendor/cache/
+vendor/cache/
+chromedriver.log
@@ -44,9 +44,10 @@ a
font-family: saxMonoRegular
font-size: 1.1em
background-color: $session-bg-color
- padding: 0.5em
a
+link-colors($session-color)
+ +hover-link
+ padding: 0.5em 1em 0.5em 1em
display: inline-block
#container
@@ -28,6 +28,6 @@
- if current_user.admin?
|
- = link_to 'Destroy', article, :confirm => 'Are you sure?', :method => :delete
+ = link_to 'Unpublish', article, :confirm => 'Are you sure?', :method => :delete
- else
= link_to 'Publish', publish_article_path(article), :method => :post, :confirm => "Are you sure?"
@@ -9,7 +9,7 @@ Feature: Articles index
@anonymous_visitor
Scenario: Visit articles index page as anonymous visitor
- But I should not be able to add/edit/destroy an article
+ But I should not be able to add/edit/unpublish an article
@editor
Scenario: Visit articles index page as editor
@@ -18,6 +18,6 @@ Feature: Articles index
@admin
Scenario: Visit articles index page as administrator
- And I should be able to add/edit/destroy an article
+ And I should be able to add/edit/unpublish an article
@@ -1,14 +0,0 @@
-@admin
-Feature: Destroy article
- In order to remove information from the wiki
- As an editor
- I want to destroy an article
-
- Scenario:
- Given 2 articles exist
- And I visit the articles index page
- And I see the two articles
- When I delete one of them
- Then I should be redirected to the articles index page
- And I should see the article remaining in the database
- But I should not see the one deleted
@@ -0,0 +1,24 @@
+@editor
+Feature: Preview article
+ In order to see the article I'm writing
+ As a editor
+ I want to preview its content
+
+ Background:
+ Given an article exists
+ And I visit its show page
+ And I click on 'Edit'
+ And I change the body to 'Lorem ipsum dolor sit amet.'
+
+ @javascript
+ Scenario: Previewing the body
+ When I click on 'Preview'
+ Then I should see a preview of new body
+
+ @javascript
+ Scenario: Back to Edit
+ And I click on 'Preview'
+ And I see a preview of new body
+ When I click on 'Back to Edit'
+ Then the preview should be hidden
+ And I should see the edit form again
@@ -0,0 +1,14 @@
+@admin
+Feature: Restore article
+ In order to publish again previously deleted information
+ As an administrator
+ I want to restore an unpublished article
+
+ Scenario:
+ Given 2 articles exist
+ And I visit the articles index page
+ And I unpublish one of them
+ And I see the unpublished article in the unpublished article list
+ When I restore it
+ Then I should be redirected to the articles index page
+ Then I should see the 2 articles in the published articles list
@@ -23,22 +23,22 @@
end
end
-Then /^I should not be able to add\/edit\/destroy an article$/ do
+Then /^I should not be able to add\/edit\/unpublish an article$/ do
page.should have_no_content('New Article')
CargoWiki::Article.all.each do |article|
within("#article-#{article.id} .actions") do
page.should have_no_content('Edit')
- page.should have_no_content('Destroy')
+ page.should have_no_content('Unpublish')
end
end
end
-Then /^I should be able to add\/edit\/destroy an article$/ do
+Then /^I should be able to add\/edit\/unpublish an article$/ do
page.should have_content('New Article')
CargoWiki::Article.all.each do |article|
within("#article-#{article.id} .actions") do
page.should have_content('Edit')
- page.should have_content('Destroy')
+ page.should have_content('Unpublish')
end
end
end
@@ -44,4 +44,4 @@
end
Given /^I do not write the commit message$/ do
-end
+end
@@ -0,0 +1,29 @@
+When /^I click on 'Preview'$/ do
+ click_link "Preview"
+end
+
+Then /^I should see a preview of new body$/ do
+ within('#article-preview .body') do
+ page.should have_content('Lorem ipsum dolor sit amet.')
+ end
+end
+
+Given /^I see a preview of new body$/ do
+ within('#article-preview .body') do
+ page.should have_content('Lorem ipsum dolor sit amet.')
+ end
+end
+
+When /^I click on 'Back to Edit'$/ do
+ click_link 'Back to Edit'
+end
+
+Then /^the preview should be hidden$/ do
+ page.should_not have_selector('#article-preview')
+end
+
+Then /^I should see the edit form again$/ do
+ within('form.article') do
+ page.should have_selector('textarea#article_body', :value => "Lorem ipsum dolor sit amet.")
+ end
+end
@@ -0,0 +1,23 @@
+Given /^I see the unpublished article in the unpublished article list$/ do
+ within('.unpublished-articles .list') do
+ page.should have_css("#article-#{@article_id}")
+ end
+end
+
+When /^I restore it$/ do
+ within("#article-#{@article_id}") do
+ click_link "Publish"
+ end
+end
+
+Then /^I should see the (\d+) articles in the published articles list$/ do |arg1|
+ within(".articles .list") do
+ CargoWiki::Article.all.each do |article|
+ within("#article-#{article.id}") do
+ page.should have_content(article.title)
+ page.should have_content(article.author.username)
+ page.should have_content(article.last_update_by.username)
+ end
+ end
+ end
+end
@@ -10,24 +10,24 @@
end
end
-When /^I delete one of them$/ do
+When /^I unpublish one of them$/ do
@article_id = CargoWiki::Article.last.id
- within("#article-#{@article_id}") { click_link("Destroy") }
+ within("#article-#{@article_id}") { click_link("Unpublish") }
end
Then /^I should be redirected to the articles index page$/ do
current_path.should == "/cargo_wiki/articles"
end
-Then /^I should see the article remaining in the database$/ do
- article = CargoWiki::Article.first
- within('.articles .list') do
- within("#article-#{article.id}") { page.should have_content(article.title) }
+Then /^I should see the unpublished article in the unpublished article list$/ do
+ within('.unpublished-articles .list') do
+ page.should have_css("#article-#{@article_id}")
end
end
-Then /^I should not see the one deleted$/ do
+Then /^I should see the other one in the published articles list$/ do
+ article = CargoWiki::Article.first
within('.articles .list') do
- page.should_not have_css("#article-#{@article_id}")
+ within("#article-#{article.id}") { page.should have_content(article.title) }
end
end
View
@@ -12,6 +12,11 @@
Dir.glob(File.expand_path("../../../spec/factories/*.rb", __FILE__)).each { |f| require f }
require 'factory_girl/step_definitions'
+Capybara.register_driver :chrome do |app|
+ Capybara::Selenium::Driver.new(app, :browser => :chrome)
+end
+Capybara.javascript_driver = :chrome
+
# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
# order to ease the transition to Capybara we set the default here. If you'd
# prefer to use XPath just remove this line and adjust any selectors in your
@@ -0,0 +1,14 @@
+@admin
+Feature: Unpublish article
+ In order to remove information from the wiki
+ As an adminisrator
+ I want to unpublish an article
+
+ Scenario:
+ Given 2 articles exist
+ And I visit the articles index page
+ And I see the two articles
+ When I unpublish one of them
+ Then I should be redirected to the articles index page
+ And I should see the unpublished article in the unpublished article list
+ And I should see the other one in the published articles list

0 comments on commit a33478e

Please sign in to comment.