aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUģis Ozols <ugis.ozolss@gmail.com>2013-06-27 09:25:19 +0300
committerUģis Ozols <ugis.ozolss@gmail.com>2013-06-27 09:25:19 +0300
commit7a76219d721d6e07a8b99dd3bbcfb87136d05052 (patch)
tree133c48dca98cd416eda5b9e185d28d5972cd7051
parenta8af874920fff981eb535d100d736f2a0017f266 (diff)
downloadrefinerycms-blog-7a76219d721d6e07a8b99dd3bbcfb87136d05052.tar.gz
refinerycms-blog-7a76219d721d6e07a8b99dd3bbcfb87136d05052.tar.bz2
refinerycms-blog-7a76219d721d6e07a8b99dd3bbcfb87136d05052.zip
Update specs due to recent Capybara/FactoryGirl upgrade.
-rw-r--r--Guardfile6
-rw-r--r--app/controllers/refinery/blog/admin/posts_controller.rb2
-rw-r--r--spec/factories/blog_posts.rb4
-rw-r--r--spec/features/refinery/blog/admin/categories_spec.rb (renamed from spec/requests/refinery/blog/admin/categories_spec.rb)4
-rw-r--r--spec/features/refinery/blog/admin/comments_spec.rb (renamed from spec/requests/refinery/blog/admin/comments_spec.rb)16
-rw-r--r--spec/features/refinery/blog/admin/menu_spec.rb (renamed from spec/requests/refinery/blog/admin/menu_spec.rb)0
-rw-r--r--spec/features/refinery/blog/admin/posts_spec.rb (renamed from spec/requests/refinery/blog/admin/posts_spec.rb)56
-rw-r--r--spec/features/refinery/blog/categories_spec.rb (renamed from spec/requests/refinery/blog/categories_spec.rb)4
-rw-r--r--spec/features/refinery/blog/posts_spec.rb (renamed from spec/requests/refinery/blog/posts_spec.rb)21
-rw-r--r--spec/models/refinery/blog/post_spec.rb6
10 files changed, 62 insertions, 57 deletions
diff --git a/Guardfile b/Guardfile
index 3e7844e..b8bb85a 100644
--- a/Guardfile
+++ b/Guardfile
@@ -2,9 +2,9 @@ guard 'rspec', :version => 2, :cli => "--color" do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
- watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/controllers/#{m[1]}_#{m[2]}_spec.rb", "spec/requests/#{m[1]}_spec.rb"] }
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/controllers/#{m[1]}_#{m[2]}_spec.rb", "spec/features/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('spec/spec_helper.rb') { "spec" }
- # Capybara request specs
- watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
+ # Capybara feature specs
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
end
diff --git a/app/controllers/refinery/blog/admin/posts_controller.rb b/app/controllers/refinery/blog/admin/posts_controller.rb
index b5d7e63..6a18a1c 100644
--- a/app/controllers/refinery/blog/admin/posts_controller.rb
+++ b/app/controllers/refinery/blog/admin/posts_controller.rb
@@ -81,7 +81,7 @@ module Refinery
end
def find_all_categories
- @categories = Refinery::Blog::Category.find(:all)
+ @categories = Refinery::Blog::Category.all
end
def check_category_ids
diff --git a/spec/factories/blog_posts.rb b/spec/factories/blog_posts.rb
index eebad3c..ff4cf16 100644
--- a/spec/factories/blog_posts.rb
+++ b/spec/factories/blog_posts.rb
@@ -5,8 +5,8 @@ FactoryGirl.define do
draft false
tag_list "chicago, shopping, fun times"
published_at Time.now
- author { Factory(:refinery_user) }
-
+ author { FactoryGirl.create(:refinery_user) }
+
factory :blog_post_draft do
draft true
end
diff --git a/spec/requests/refinery/blog/admin/categories_spec.rb b/spec/features/refinery/blog/admin/categories_spec.rb
index 9d4ddf3..f3cdc5a 100644
--- a/spec/requests/refinery/blog/admin/categories_spec.rb
+++ b/spec/features/refinery/blog/admin/categories_spec.rb
@@ -20,9 +20,9 @@ describe "Categories admin" do
end
context "with translations" do
- before(:each) do
+ before do
Refinery::I18n.stub(:frontend_locales).and_return([:en, :ru])
- blog_page = Globalize.with_locale(:en) { Factory.create(:page, :link_url => "/blog", :title => "Blog") }
+ blog_page = Globalize.with_locale(:en) { FactoryGirl.create(:page, :link_url => "/blog", :title => "Blog") }
Globalize.with_locale(:ru) do
blog_page.title = 'блог'
blog_page.save
diff --git a/spec/requests/refinery/blog/admin/comments_spec.rb b/spec/features/refinery/blog/admin/comments_spec.rb
index c834d13..08fe9df 100644
--- a/spec/requests/refinery/blog/admin/comments_spec.rb
+++ b/spec/features/refinery/blog/admin/comments_spec.rb
@@ -5,10 +5,10 @@ module Refinery
module Admin
describe Comment do
refinery_login_with :refinery_user
-
+
describe "#index" do
context "when has no new unapproved comments" do
- before(:each) do
+ before do
subject.class.delete_all
visit refinery.blog_admin_comments_path
end
@@ -21,7 +21,7 @@ module Refinery
end
context "when has new unapproved comments" do
let!(:blog_comment) { FactoryGirl.create(:blog_comment) }
- before(:each) { visit refinery.blog_admin_comments_path }
+ before { visit refinery.blog_admin_comments_path }
it "should list comments" do
page.should have_content(blog_comment.body)
@@ -44,7 +44,7 @@ module Refinery
describe "#approved" do
context "when has no approved comments" do
- before(:each) do
+ before do
subject.class.delete_all
visit refinery.approved_blog_admin_comments_path
end
@@ -57,7 +57,7 @@ module Refinery
let!(:blog_comment) do
FactoryGirl.create(:blog_comment, :state => 'approved')
end
- before(:each) { visit refinery.approved_blog_admin_comments_path }
+ before { visit refinery.approved_blog_admin_comments_path }
it "should list comments" do
page.should have_content(blog_comment.body)
@@ -74,7 +74,7 @@ module Refinery
describe "#rejected" do
context "when has no rejected comments" do
- before(:each) do
+ before do
subject.class.delete_all
visit refinery.rejected_blog_admin_comments_path
end
@@ -87,7 +87,7 @@ module Refinery
let!(:blog_comment) do
FactoryGirl.create(:blog_comment, :state => 'rejected')
end
- before(:each) { visit refinery.rejected_blog_admin_comments_path }
+ before { visit refinery.rejected_blog_admin_comments_path }
it "should list comments" do
page.should have_content(blog_comment.body)
@@ -104,7 +104,7 @@ module Refinery
describe "#show" do
let!(:blog_comment) { FactoryGirl.create(:blog_comment) }
- before(:each) { visit refinery.blog_admin_comment_path(blog_comment) }
+ before { visit refinery.blog_admin_comment_path(blog_comment) }
it "should display the comment" do
page.should have_content(blog_comment.body)
page.should have_content(blog_comment.name)
diff --git a/spec/requests/refinery/blog/admin/menu_spec.rb b/spec/features/refinery/blog/admin/menu_spec.rb
index ba10ffe..ba10ffe 100644
--- a/spec/requests/refinery/blog/admin/menu_spec.rb
+++ b/spec/features/refinery/blog/admin/menu_spec.rb
diff --git a/spec/requests/refinery/blog/admin/posts_spec.rb b/spec/features/refinery/blog/admin/posts_spec.rb
index 0b3890a..a5d4f62 100644
--- a/spec/requests/refinery/blog/admin/posts_spec.rb
+++ b/spec/features/refinery/blog/admin/posts_spec.rb
@@ -7,13 +7,15 @@ module Refinery
describe Post do
refinery_login_with :refinery_user
- let!(:blog_category) { FactoryGirl.create(:blog_category, :title => "Video Games") }
+ let!(:blog_category) do
+ Globalize.with_locale(:en) { FactoryGirl.create(:blog_category) }
+ end
context "when no blog posts" do
- before(:each) { subject.class.destroy_all }
+ before { subject.class.destroy_all }
describe "blog post listing" do
- before(:each) { visit refinery.blog_admin_posts_path }
+ before { visit refinery.blog_admin_posts_path }
it "invites to create new post" do
page.should have_content("There are no Blog Posts yet. Click \"Create new post\" to add your first blog post.")
@@ -21,7 +23,7 @@ module Refinery
end
describe "new blog post form" do
- before(:each) do
+ before do
visit refinery.blog_admin_posts_path
click_link "Create new post"
end
@@ -30,14 +32,18 @@ module Refinery
page.should have_content("Tags")
end
- it "should have Video Games" do
+ it "should have category title", :js => true do
+ click_link "toggle_advanced_options"
page.should have_content(blog_category.title)
end
- describe "create blog post" do
- before(:each) do
- fill_in "Title", :with => "This is my blog post"
- fill_in "post_body", :with => "And I love it"
+ describe "create blog post", :js => true do
+ before do
+ fill_in "post_title", :with => "This is my blog post"
+ # this is a dirty hack but textarea that needs to be filled is
+ # hidden and capybara refuses to fill in elements it can't see
+ page.evaluate_script("WYMeditor.INSTANCES[0].html('<p>And I love it</p>')")
+ click_link "toggle_advanced_options"
check blog_category.title
click_button "Save"
end
@@ -60,11 +66,13 @@ module Refinery
end
end
- describe "create blog post with tags" do
- before(:each) do
+ describe "create blog post with tags", :js => true do
+ before do
@tag_list = "chicago, bikes, beers, babes"
fill_in "Title", :with => "This is a tagged blog post"
- fill_in "post_body", :with => "And I also love it"
+ # this is a dirty hack but textarea that needs to be filled is
+ # hidden and capybara refuses to fill in elements it can't see
+ page.evaluate_script("WYMeditor.INSTANCES[0].html('<p>And I also love it</p>')")
fill_in "Tags", :with => @tag_list
click_button "Save"
end
@@ -90,7 +98,7 @@ module Refinery
end
describe "blog post listing" do
- before(:each) { visit refinery.blog_admin_posts_path }
+ before { visit refinery.blog_admin_posts_path }
describe "edit blog post" do
it "should succeed" do
@@ -99,7 +107,7 @@ module Refinery
click_link("Edit this blog post")
current_path.should == refinery.edit_blog_admin_post_path(blog_post)
- fill_in "Title", :with => "hax0r"
+ fill_in "post_title", :with => "hax0r"
click_button "Save"
page.should_not have_content(blog_post.title)
@@ -146,17 +154,19 @@ module Refinery
end
context "with multiple users" do
- let!(:other_guy) { Factory(:refinery_user, :username => "Other Guy") }
+ let!(:other_guy) { FactoryGirl.create(:refinery_user, :username => "Other Guy") }
- describe "create blog post with alternate author" do
- before(:each) do
+ describe "create blog post with alternate author", :js => true do
+ before do
visit refinery.blog_admin_posts_path
click_link "Create new post"
- fill_in "Title", :with => "This is some other guy's blog post"
- fill_in "post_body", :with => "I totally didn't write it."
+ fill_in "post_title", :with => "This is some other guy's blog post"
+ # this is a dpage_titleirty hack but textarea that needs to be filled is
+ # hidden and capybara refuses to fill in elements it can't see
+ page.evaluate_script("WYMeditor.INSTANCES[0].html('<p>I totally did not write it.</p>')")
- click_link "Advanced options"
+ click_link "toggle_advanced_options"
select other_guy.username, :from => "Author"
@@ -174,10 +184,10 @@ module Refinery
end
context "with translations" do
- before(:each) do
+ before do
Globalize.locale = :en
Refinery::I18n.stub(:frontend_locales).and_return([:en, :ru])
- blog_page = Factory.create(:page, :link_url => "/blog", :title => "Blog")
+ blog_page = FactoryGirl.create(:page, :link_url => "/blog", :title => "Blog")
Globalize.with_locale(:ru) do
blog_page.title = 'блог'
blog_page.save
@@ -279,7 +289,7 @@ module Refinery
_blog_post
end
- before(:each) do
+ before do
visit refinery.blog_admin_posts_path
end
diff --git a/spec/requests/refinery/blog/categories_spec.rb b/spec/features/refinery/blog/categories_spec.rb
index ba96b1b..021dd94 100644
--- a/spec/requests/refinery/blog/categories_spec.rb
+++ b/spec/features/refinery/blog/categories_spec.rb
@@ -3,9 +3,9 @@ require "spec_helper"
module Refinery
describe "BlogCategories" do
refinery_login_with :refinery_user
-
+
context "has one category and post" do
- before(:each) do
+ before do
post = Globalize.with_locale(:en) do
FactoryGirl.create(:blog_post, :title => "Refinery CMS blog post")
end
diff --git a/spec/requests/refinery/blog/posts_spec.rb b/spec/features/refinery/blog/posts_spec.rb
index 9be8618..1fe56bc 100644
--- a/spec/requests/refinery/blog/posts_spec.rb
+++ b/spec/features/refinery/blog/posts_spec.rb
@@ -5,7 +5,9 @@ module Refinery
refinery_login_with :refinery_user
context "when has blog posts" do
- let!(:blog_post) { Globalize.with_locale(:en) { FactoryGirl.create(:blog_post, :title => "Refinery CMS blog post") } }
+ let!(:blog_post) do
+ Globalize.with_locale(:en) { FactoryGirl.create(:blog_post, :title => "Refinery CMS blog post") }
+ end
it "should display blog post" do
visit refinery.blog_post_path(blog_post)
@@ -13,18 +15,11 @@ module Refinery
page.should have_content(blog_post.title)
end
- it "should display the blog rss feed" do
- get refinery.blog_rss_feed_path
-
- response.should be_success
- response.content_type.should eq("application/rss+xml")
- end
-
describe "visit blog" do
- before(:each) do
- Factory.create(:page, :link_url => "/")
- Factory.create(:page, :link_url => "/blog", :title => "Blog")
+ before do
+ FactoryGirl.create(:page, :link_url => "/")
+ FactoryGirl.create(:page, :link_url => "/blog", :title => "Blog")
end
it "shows blog link in menu" do
@@ -46,7 +41,7 @@ module Refinery
describe "list tagged posts" do
context "when has tagged blog posts" do
- before(:each) do
+ before do
@tag_name = "chicago"
@post = FactoryGirl.create(:blog_post,
:title => "I Love my city",
@@ -102,7 +97,7 @@ module Refinery
end
context "when posting comments" do
- let(:blog_post) { Factory(:blog_post) }
+ let(:blog_post) { FactoryGirl.create(:blog_post) }
let(:name) { "pete" }
let(:email) { "pete@mcawesome.com" }
let(:body) { "Witty comment." }
diff --git a/spec/models/refinery/blog/post_spec.rb b/spec/models/refinery/blog/post_spec.rb
index 84e9c87..cec6a2f 100644
--- a/spec/models/refinery/blog/post_spec.rb
+++ b/spec/models/refinery/blog/post_spec.rb
@@ -114,15 +114,15 @@ module Refinery
describe "#live?" do
it "returns true if post is not in draft and it's published" do
- Factory.build(:blog_post).should be_live
+ FactoryGirl.build(:blog_post).should be_live
end
it "returns false if post is in draft" do
- Factory.build(:blog_post, :draft => true).should_not be_live
+ FactoryGirl.build(:blog_post, :draft => true).should_not be_live
end
it "returns false if post pub date is in future" do
- Factory.build(:blog_post, :published_at => Time.now.advance(:minutes => 1)).should_not be_live
+ FactoryGirl.build(:blog_post, :published_at => Time.now.advance(:minutes => 1)).should_not be_live
end
end