diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories/blog_categories.rb | 5 | ||||
-rw-r--r-- | spec/factories/blog_comments.rb | 19 | ||||
-rw-r--r-- | spec/factories/blog_posts.rb | 13 | ||||
-rw-r--r-- | spec/models/blog_category_spec.rb | 41 | ||||
-rw-r--r-- | spec/models/blog_comment_spec.rb | 21 | ||||
-rw-r--r-- | spec/models/blog_post_spec.rb | 217 | ||||
-rw-r--r-- | spec/models/refinery/blog/category_spec.rb | 42 | ||||
-rw-r--r-- | spec/models/refinery/blog/comment_spec.rb | 19 | ||||
-rw-r--r-- | spec/models/refinery/blog/post_spec.rb | 220 | ||||
-rw-r--r-- | spec/rcov.opts | 2 | ||||
-rw-r--r-- | spec/requests/refinery/admin/blog/comments_spec.rb | 124 | ||||
-rw-r--r-- | spec/requests/refinery/admin/blog/posts_spec.rb | 143 | ||||
-rw-r--r-- | spec/requests/refinery/blog/categories_spec.rb | 25 | ||||
-rw-r--r-- | spec/requests/refinery/blog/posts_spec.rb | 109 | ||||
-rw-r--r-- | spec/spec_helper.rb | 38 | ||||
-rw-r--r-- | spec/support/database_cleaner.rb | 17 | ||||
-rw-r--r-- | spec/support/devise.rb | 8 | ||||
-rw-r--r-- | spec/support/refinery.rb | 6 |
18 files changed, 790 insertions, 279 deletions
diff --git a/spec/factories/blog_categories.rb b/spec/factories/blog_categories.rb new file mode 100644 index 0000000..82f629b --- /dev/null +++ b/spec/factories/blog_categories.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :blog_category, :class => Refinery::Blog::Category do + sequence(:title) { |n| "Shopping #{n}" } + end +end diff --git a/spec/factories/blog_comments.rb b/spec/factories/blog_comments.rb new file mode 100644 index 0000000..e0309b2 --- /dev/null +++ b/spec/factories/blog_comments.rb @@ -0,0 +1,19 @@ +FactoryGirl.define do + factory :blog_comment, :class => Refinery::Blog::Comment do + name "Joe Commenter" + sequence(:email) { |n| "person#{n}@example.com" } + body "Which one is the best for picking up new shoes?" + association :post, :factory => :blog_post + + trait :approved do + state 'approved' + end + + trait :rejected do + state 'rejected' + end + + factory :approved_comment, :traits => [:approved] + factory :rejected_comment, :traits => [:rejected] + end +end diff --git a/spec/factories/blog_posts.rb b/spec/factories/blog_posts.rb new file mode 100644 index 0000000..1ad2bd2 --- /dev/null +++ b/spec/factories/blog_posts.rb @@ -0,0 +1,13 @@ +FactoryGirl.define do + factory :blog_post, :class => Refinery::Blog::Post do + sequence(:title) { |n| "Top #{n} Shopping Centers in Chicago" } + body "These are the top ten shopping centers in Chicago. You're going to read a long blog post about them. Come to peace with it." + draft false + tag_list "chicago, shopping, fun times" + published_at Time.now + + factory :blog_post_draft do + draft true + end + end +end diff --git a/spec/models/blog_category_spec.rb b/spec/models/blog_category_spec.rb deleted file mode 100644 index 7792744..0000000 --- a/spec/models/blog_category_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -require 'spec_helper' -Dir[File.expand_path('../../../features/support/factories/*.rb', __FILE__)].each{|factory| require factory} - -describe BlogCategory do - before(:each) do - @blog_category = Factory.create(:blog_category) - end - - describe "validations" do - it "requires title" do - Factory.build(:blog_category, :title => "").should_not be_valid - end - - it "won't allow duplicate titles" do - Factory.build(:blog_category, :title => @blog_category.title).should_not be_valid - end - end - - describe "blog posts association" do - it "has a posts attribute" do - @blog_category.should respond_to(:posts) - end - - it "returns posts by published_at date in descending order" do - first_post = @blog_category.posts.create!({ :title => "Breaking News: Joe Sak is hot stuff you guys!!", :body => "True story.", :published_at => Time.now.yesterday }) - latest_post = @blog_category.posts.create!({ :title => "parndt is p. okay", :body => "For a Kiwi.", :published_at => Time.now }) - - @blog_category.posts.first.should == latest_post - end - - end - - describe "#post_count" do - it "returns post count in category" do - 2.times do - @blog_category.posts << Factory.create(:blog_post) - end - @blog_category.post_count.should == 2 - end - end -end diff --git a/spec/models/blog_comment_spec.rb b/spec/models/blog_comment_spec.rb deleted file mode 100644 index feb2860..0000000 --- a/spec/models/blog_comment_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'spec_helper' -Dir[File.expand_path('../../../features/support/factories/*.rb', __FILE__)].each{|factory| require factory} - -describe BlogComment do - - context "wiring up" do - - before(:each) do - @comment = Factory.create(:blog_comment) - end - - it "saves" do - @comment.should_not be_nil - end - - it "has a blog post" do - @comment.post.should_not be_nil - end - - end -end diff --git a/spec/models/blog_post_spec.rb b/spec/models/blog_post_spec.rb deleted file mode 100644 index afe82cc..0000000 --- a/spec/models/blog_post_spec.rb +++ /dev/null @@ -1,217 +0,0 @@ -require 'spec_helper' -Dir[File.expand_path('../../../features/support/factories/*.rb', __FILE__)].each{|factory| require factory} - -describe BlogPost do - let(:blog_post ) { Factory.create(:blog_post) } - - describe "validations" do - it "requires title" do - Factory.build(:blog_post, :title => "").should_not be_valid - end - - it "won't allow duplicate titles" do - Factory.build(:blog_post, :title => blog_post.title).should_not be_valid - end - - it "requires body" do - Factory.build(:blog_post, :body => nil).should_not be_valid - end - end - - describe "comments association" do - - it "have a comments attribute" do - blog_post.should respond_to(:comments) - end - - it "destroys associated comments" do - Factory.create(:blog_comment, :blog_post_id => blog_post.id) - blog_post.destroy - BlogComment.find_by_blog_post_id(blog_post.id).should == nil - end - end - - describe "categories association" do - it "have categories attribute" do - blog_post.should respond_to(:categories) - end - end - - describe "tags" do - it "acts as taggable" do - blog_post.should respond_to(:tag_list) - - #the factory has default tags, including 'chicago' - blog_post.tag_list.should include("chicago") - end - end - - describe "authors" do - it "are authored" do - BlogPost.instance_methods.map(&:to_sym).should include(:author) - end - end - - describe "by_archive scope" do - before do - @blog_post1 = Factory.create(:blog_post, :published_at => Date.new(2011, 3, 11)) - @blog_post2 = Factory.create(:blog_post, :published_at => Date.new(2011, 3, 12)) - - #2 months before - Factory.create(:blog_post, :published_at => Date.new(2011, 1, 10)) - end - - it "returns all posts from specified month" do - #check for this month - date = "03/2011" - BlogPost.by_archive(Time.parse(date)).count.should be == 2 - BlogPost.by_archive(Time.parse(date)).should == [@blog_post2, @blog_post1] - end - end - - describe "all_previous scope" do - before do - @blog_post1 = Factory.create(:blog_post, :published_at => Time.now - 2.months) - @blog_post2 = Factory.create(:blog_post, :published_at => Time.now - 1.month) - Factory.create(:blog_post, :published_at => Time.now) - end - - it "returns all posts from previous months" do - BlogPost.all_previous.count.should be == 2 - BlogPost.all_previous.should == [@blog_post2, @blog_post1] - end - end - - describe "live scope" do - before do - @blog_post1 = Factory.create(:blog_post, :published_at => Time.now.advance(:minutes => -2)) - @blog_post2 = Factory.create(:blog_post, :published_at => Time.now.advance(:minutes => -1)) - Factory.create(:blog_post, :draft => true) - Factory.create(:blog_post, :published_at => Time.now + 1.minute) - end - - it "returns all posts which aren't in draft and pub date isn't in future" do - BlogPost.live.count.should be == 2 - BlogPost.live.should == [@blog_post2, @blog_post1] - end - end - - describe "uncategorized scope" do - before do - @uncategorized_blog_post = Factory.create(:blog_post) - @categorized_blog_post = Factory.create(:blog_post) - - @categorized_blog_post.categories << Factory.create(:blog_category) - end - - it "returns uncategorized posts if they exist" do - BlogPost.uncategorized.should include @uncategorized_blog_post - BlogPost.uncategorized.should_not include @categorized_blog_post - end - end - - describe "#live?" do - it "returns true if post is not in draft and it's published" do - Factory.create(:blog_post).live?.should be_true - end - - it "returns false if post is in draft" do - Factory.create(:blog_post, :draft => true).live?.should be_false - end - - it "returns false if post pub date is in future" do - Factory.create(:blog_post, :published_at => Time.now.advance(:minutes => 1)).live?.should be_false - end - end - - describe "#next" do - before do - Factory.create(:blog_post, :published_at => Time.now.advance(:minutes => -1)) - @blog_post = Factory.create(:blog_post) - end - - it "returns next article when called on current article" do - BlogPost.last.next.should == @blog_post - end - end - - describe "#prev" do - before do - Factory.create(:blog_post) - @blog_post = Factory.create(:blog_post, :published_at => Time.now.advance(:minutes => -1)) - end - - it "returns previous article when called on current article" do - BlogPost.first.prev.should == @blog_post - end - end - - describe "#category_ids=" do - before do - @cat1 = Factory.create(:blog_category, :id => 1) - @cat2 = Factory.create(:blog_category, :id => 2) - @cat3 = Factory.create(:blog_category, :id => 3) - blog_post.category_ids = [1,2,"","",3] - end - - it "rejects blank category ids" do - blog_post.categories.count.should == 3 - end - - it "returns array of categories based on given ids" do - blog_post.categories.should == [@cat1, @cat2, @cat3] - end - end - - describe ".comments_allowed?" do - context "with RefinerySetting comments_allowed set to true" do - before do - RefinerySetting.set(:comments_allowed, { :scoping => 'blog', :value => true }) - end - - it "should be true" do - BlogPost.comments_allowed?.should be_true - end - end - - context "with RefinerySetting comments_allowed set to false" do - before do - RefinerySetting.set(:comments_allowed, { :scoping => 'blog', :value => false }) - end - - it "should be false" do - BlogPost.comments_allowed?.should be_false - end - end - end - - describe "custom teasers" do - it "should allow a custom teaser" do - Factory.create(:blog_post, :custom_teaser => 'This is some custom content').should be_valid - end - end - - describe ".teasers_enabled?" do - context "with RefinerySetting teasers_enabled set to true" do - before do - RefinerySetting.set(:teasers_enabled, { :scoping => 'blog', :value => true }) - end - - it "should be true" do - BlogPost.teasers_enabled?.should be_true - end - end - - context "with RefinerySetting teasers_enabled set to false" do - before do - RefinerySetting.set(:teasers_enabled, { :scoping => 'blog', :value => false }) - end - - it "should be false" do - BlogPost.teasers_enabled?.should be_false - end - end - - end - -end diff --git a/spec/models/refinery/blog/category_spec.rb b/spec/models/refinery/blog/category_spec.rb new file mode 100644 index 0000000..9c4a7d3 --- /dev/null +++ b/spec/models/refinery/blog/category_spec.rb @@ -0,0 +1,42 @@ +require 'spec_helper' + +module Refinery + module Blog + describe Category do + let(:category) { FactoryGirl.create(:blog_category) } + + describe "validations" do + it "requires title" do + FactoryGirl.build(:blog_category, :title => "").should_not be_valid + end + + it "won't allow duplicate titles" do + FactoryGirl.build(:blog_category, :title => category.title).should_not be_valid + end + end + + describe "blog posts association" do + it "has a posts attribute" do + category.should respond_to(:posts) + end + + it "returns posts by published_at date in descending order" do + first_post = category.posts.create!({ :title => "Breaking News: Joe Sak is hot stuff you guys!!", :body => "True story.", :published_at => Time.now.yesterday }) + latest_post = category.posts.create!({ :title => "parndt is p. okay", :body => "For a Kiwi.", :published_at => Time.now }) + + category.posts.first.should == latest_post + end + + end + + describe "#post_count" do + it "returns post count in category" do + 2.times do + category.posts << FactoryGirl.create(:blog_post) + end + category.post_count.should == 2 + end + end + end + end +end
\ No newline at end of file diff --git a/spec/models/refinery/blog/comment_spec.rb b/spec/models/refinery/blog/comment_spec.rb new file mode 100644 index 0000000..3a77100 --- /dev/null +++ b/spec/models/refinery/blog/comment_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +module Refinery + module Blog + describe Comment do + context "wiring up" do + let(:comment) { FactoryGirl.create(:blog_comment) } + + it "saves" do + comment.should_not be_nil + end + + it "has a blog post" do + comment.post.should_not be_nil + end + end + end + end +end diff --git a/spec/models/refinery/blog/post_spec.rb b/spec/models/refinery/blog/post_spec.rb new file mode 100644 index 0000000..7167728 --- /dev/null +++ b/spec/models/refinery/blog/post_spec.rb @@ -0,0 +1,220 @@ +require 'spec_helper' + +module Refinery + module Blog + describe Post do + let(:post) { FactoryGirl.create(:blog_post) } + + describe "validations" do + it "requires title" do + FactoryGirl.build(:blog_post, :title => "").should_not be_valid + end + + it "won't allow duplicate titles" do + FactoryGirl.build(:blog_post, :title => post.title).should_not be_valid + end + + it "requires body" do + FactoryGirl.build(:blog_post, :body => nil).should_not be_valid + end + end + + describe "comments association" do + + it "have a comments attribute" do + post.should respond_to(:comments) + end + + it "destroys associated comments" do + FactoryGirl.create(:blog_comment, :blog_post_id => post.id) + post.destroy + Blog::Comment.where(:blog_post_id => post.id).should be_empty + end + end + + describe "categories association" do + it "have categories attribute" do + post.should respond_to(:categories) + end + end + + describe "tags" do + it "acts as taggable" do + post.should respond_to(:tag_list) + + #the factory has default tags, including 'chicago' + post.tag_list.should include("chicago") + end + end + + describe "authors" do + it "are authored" do + subject.class.instance_methods.map(&:to_sym).should include(:author) + end + end + + describe "by_archive scope" do + before do + @blog_post1 = FactoryGirl.create(:blog_post, :published_at => Date.new(2011, 3, 11)) + @blog_post2 = FactoryGirl.create(:blog_post, :published_at => Date.new(2011, 3, 12)) + + #2 months before + FactoryGirl.create(:blog_post, :published_at => Date.new(2011, 1, 10)) + end + + it "returns all posts from specified month" do + #check for this month + date = "03/2011" + subject.class.by_archive(Time.parse(date)).count.should be == 2 + subject.class.by_archive(Time.parse(date)).should == [@blog_post2, @blog_post1] + end + end + + describe "all_previous scope" do + before do + @blog_post1 = FactoryGirl.create(:blog_post, :published_at => Time.now - 2.months) + @blog_post2 = FactoryGirl.create(:blog_post, :published_at => Time.now - 1.month) + FactoryGirl.create(:blog_post, :published_at => Time.now) + end + + it "returns all posts from previous months" do + subject.class.all_previous.count.should be == 2 + subject.class.all_previous.should == [@blog_post2, @blog_post1] + end + end + + describe "live scope" do + before do + @blog_post1 = FactoryGirl.create(:blog_post, :published_at => Time.now.advance(:minutes => -2)) + @blog_post2 = FactoryGirl.create(:blog_post, :published_at => Time.now.advance(:minutes => -1)) + FactoryGirl.create(:blog_post, :draft => true) + FactoryGirl.create(:blog_post, :published_at => Time.now + 1.minute) + end + + it "returns all posts which aren't in draft and pub date isn't in future" do + subject.class.live.count.should be == 2 + subject.class.live.should == [@blog_post2, @blog_post1] + end + end + + describe "uncategorized scope" do + before do + @uncategorized_post = FactoryGirl.create(:blog_post) + @categorized_post = FactoryGirl.create(:blog_post) + + @categorized_post.categories << FactoryGirl.create(:blog_category) + end + + it "returns uncategorized posts if they exist" do + subject.class.uncategorized.should include @uncategorized_post + subject.class.uncategorized.should_not include @categorized_post + end + end + + describe "#live?" do + it "returns true if post is not in draft and it's published" do + FactoryGirl.create(:blog_post).live?.should be_true + end + + it "returns false if post is in draft" do + FactoryGirl.create(:blog_post, :draft => true).live?.should be_false + end + + it "returns false if post pub date is in future" do + FactoryGirl.create(:blog_post, :published_at => Time.now.advance(:minutes => 1)).live?.should be_false + end + end + + describe "#next" do + before do + FactoryGirl.create(:blog_post, :published_at => Time.now.advance(:minutes => -1)) + @blog_post = FactoryGirl.create(:blog_post) + end + + it "returns next article when called on current article" do + subject.class.last.next.should == @blog_post + end + end + + describe "#prev" do + before do + FactoryGirl.create(:blog_post) + @blog_post = FactoryGirl.create(:blog_post, :published_at => Time.now.advance(:minutes => -1)) + end + + it "returns previous article when called on current article" do + subject.class.first.prev.should == @blog_post + end + end + + describe "#category_ids=" do + before do + @cat1 = FactoryGirl.create(:blog_category, :id => 1) + @cat2 = FactoryGirl.create(:blog_category, :id => 2) + @cat3 = FactoryGirl.create(:blog_category, :id => 3) + post.category_ids = [1,2,"","",3] + end + + it "rejects blank category ids" do + post.categories.count.should == 3 + end + + it "returns array of categories based on given ids" do + post.categories.should == [@cat1, @cat2, @cat3] + end + end + + describe ".comments_allowed?" do + context "with Refinery::Setting comments_allowed set to true" do + before do + Refinery::Setting.set(:comments_allowed, { :scoping => 'blog', :value => true }) + end + + it "should be true" do + subject.class.comments_allowed?.should be_true + end + end + + context "with Refinery::Setting comments_allowed set to false" do + before do + Refinery::Setting.set(:comments_allowed, { :scoping => 'blog', :value => false }) + end + + it "should be false" do + subject.class.comments_allowed?.should be_false + end + end + end + + describe "custom teasers" do + it "should allow a custom teaser" do + FactoryGirl.create(:blog_post, :custom_teaser => 'This is some custom content').should be_valid + end + end + + describe ".teasers_enabled?" do + context "with Refinery::Setting teasers_enabled set to true" do + before do + Refinery::Setting.set(:teasers_enabled, { :scoping => 'blog', :value => true }) + end + + it "should be true" do + subject.class.teasers_enabled?.should be_true + end + end + + context "with Refinery::Setting teasers_enabled set to false" do + before do + Refinery::Setting.set(:teasers_enabled, { :scoping => 'blog', :value => false }) + end + + it "should be false" do + subject.class.teasers_enabled?.should be_false + end + end + + end + + end + end +end
\ No newline at end of file diff --git a/spec/rcov.opts b/spec/rcov.opts new file mode 100644 index 0000000..274ed51 --- /dev/null +++ b/spec/rcov.opts @@ -0,0 +1,2 @@ +--exclude "spec/*,gems/*" +--rails
\ No newline at end of file diff --git a/spec/requests/refinery/admin/blog/comments_spec.rb b/spec/requests/refinery/admin/blog/comments_spec.rb new file mode 100644 index 0000000..a7367e3 --- /dev/null +++ b/spec/requests/refinery/admin/blog/comments_spec.rb @@ -0,0 +1,124 @@ +require "spec_helper" + +module Refinery + describe "AdminBlog::Comments" do + login_refinery_user + + describe "#index" do + context "when has no new unapproved comments" do + before(:each) do + Blog::Comment.delete_all + visit refinery_admin_blog_comments_path + end + + it "should list no comments" do + visit refinery_admin_blog_comments_path + + page.should have_content('there are no new comments') + end + end + + context "when has new unapproved comments" do + let!(:blog_comment) { FactoryGirl.create(:blog_comment) } + before(:each) { visit refinery_admin_blog_comments_path } + + it "should list comments" do + page.should have_content(blog_comment.body) + page.should have_content(blog_comment.name) + end + + it "should allow me to approve a comment" do + click_link "Approve this comment" + + page.should have_content("has been approved") + end + + it "should allow me to reject a comment" do + click_link "Reject this comment" + + page.should have_content("has been rejected") + end + end + end + + describe "#approved" do + context "when has no approved comments" do + before(:each) do + Blog::Comment.delete_all + visit approved_refinery_admin_blog_comments_path + end + + it "should list no comments" do + page.should have_content('there are no approved comments') + end + end + + context "when has approved comments" do + let!(:blog_comment) do + FactoryGirl.create(:blog_comment, + :state => 'approved') + end + before(:each) { visit approved_refinery_admin_blog_comments_path } + + it "should list comments" do + page.should have_content(blog_comment.body) + page.should have_content(blog_comment.name) + end + + it "should allow me to reject a comment" do + click_link "Reject this comment" + + page.should have_content("has been rejected") + end + end + end + + describe "#rejected" do + context "when has no rejected comments" do + before(:each) do + Blog::Comment.delete_all + visit rejected_refinery_admin_blog_comments_path + end + + it "should list no comments" do + page.should have_content('there are no rejected comments') + end + end + + context "when has rejected comments" do + let!(:blog_comment) do + FactoryGirl.create(:blog_comment, + :state => 'rejected') + end + before(:each) { visit rejected_refinery_admin_blog_comments_path } + + it "should list comments" do + page.should have_content(blog_comment.body) + page.should have_content(blog_comment.name) + end + + it "should allow me to approve a comment" do + click_link "Approve this comment" + + page.should have_content("has been approved") + end + end + end + + describe "#show" do + let!(:blog_comment) { FactoryGirl.create(:blog_comment) } + before(:each) { visit refinery_admin_blog_comment_path(blog_comment) } + + it "should display the comment" do + page.should have_content(blog_comment.body) + page.should have_content(blog_comment.name) + end + + it "should allow me to approve the comment" do + click_link "Approve this comment" + + page.should have_content("has been approved") + end + end + end +end diff --git a/spec/requests/refinery/admin/blog/posts_spec.rb b/spec/requests/refinery/admin/blog/posts_spec.rb new file mode 100644 index 0000000..08fbab9 --- /dev/null +++ b/spec/requests/refinery/admin/blog/posts_spec.rb @@ -0,0 +1,143 @@ +require "spec_helper" + +module Refinery + describe "AdminBlog::Posts" do + login_refinery_user + + let!(:blog_category) { FactoryGirl.create(:blog_category, :title => "Video Games") } + + context "when no blog posts" do + before(:each) { Refinery::Blog::Post.destroy_all } + + describe "blog post listing" do + before(:each) { visit refinery_admin_blog_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.") + end + end + + describe "new blog post form" do + before(:each) do + visit refinery_admin_blog_posts_path + click_link "Create new post" + end + + it "should have Tags" do + page.should have_content("Tags") + end + + it "should have Video Games" do + 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 "blog_post_body", :with => "And I love it" + check blog_category.title + click_button "Save" + end + + it "should succeed" do + page.should have_content("was successfully added.") + end + + it "should be the only blog post" do + ::Refinery::Blog::Post.all.size.should eq(1) + end + + it "should belong to me" do + ::Refinery::Blog::Post.first.author.login.should eq(::Refinery::User.last.login) + end + + it "should save categories" do + ::Refinery::Blog::Post.last.categories.count.should eq(1) + ::Refinery::Blog::Post.last.categories.first.title.should eq(blog_category.title) + end + end + + describe "create blog post with tags" do + before(:each) do + @tag_list = "chicago, bikes, beers, babes" + fill_in "Title", :with => "This is a tagged blog post" + fill_in "blog_post_body", :with => "And I also love it" + fill_in "Tags", :with => @tag_list + click_button "Save" + end + + it "should succeed" do + page.should have_content("was successfully added.") + end + + it "should be the only blog post" do + ::Refinery::Blog::Post.all.size.should eq(1) + end + + it "should have the specified tags" do + ::Refinery::Blog::Post.last.tag_list.should eq(@tag_list.split(', ')) + end + end + end + end + + context "when has blog posts" do + let!(:blog_post) { FactoryGirl.create(:blog_post) } + + describe "blog post listing" do + before(:each) { visit refinery_admin_blog_posts_path } + + describe "edit blog post" do + it "should succeed" do + page.should have_content(blog_post.title) + + click_link("Edit this blog post") + current_path.should == edit_refinery_admin_blog_post_path(blog_post) + + fill_in "Title", :with => "hax0r" + click_button "Save" + + page.should_not have_content(blog_post.title) + page.should have_content("'hax0r' was successfully updated.") + end + end + + describe "deleting blog post" do + it "should succeed" do + page.should have_content(blog_post.title) + + click_link "Remove this blog post forever" + + page.should have_content("'#{blog_post.title}' was successfully removed.") + end + end + + describe "view live" do + it "redirects to blog post in the frontend" do + click_link "View this blog post live" + + current_path.should == blog_post_path(blog_post) + page.should have_content(blog_post.title) + end + end + end + + context "when uncategorized post" do + it "shows up in the list" do + visit uncategorized_refinery_admin_blog_posts_path + page.should have_content(blog_post.title) + end + end + + context "when categorized post" do + it "won't show up in the list" do + blog_post.categories << blog_category + blog_post.save! + + visit uncategorized_refinery_admin_blog_posts_path + page.should_not have_content(blog_post.title) + end + end + end + end +end diff --git a/spec/requests/refinery/blog/categories_spec.rb b/spec/requests/refinery/blog/categories_spec.rb new file mode 100644 index 0000000..48a3417 --- /dev/null +++ b/spec/requests/refinery/blog/categories_spec.rb @@ -0,0 +1,25 @@ +require "spec_helper" + +module Refinery + describe "BlogCategories" do + login_refinery_user + + context "has one category and post" do + before(:each) do + @blog_post = FactoryGirl.create(:blog_post, :title => "Refinery CMS blog post") + @blog_category = FactoryGirl.create(:blog_category, :title => "Video Games") + @blog_post.categories << @blog_category + @blog_post.save! + end + + describe "show categories blog posts" do + before(:each) { visit blog_category_path(@blog_category) } + + it "should displays categories blog posts" do + page.should have_content("Refinery CMS blog post") + page.should have_content("Video Games") + end + end + end + end +end diff --git a/spec/requests/refinery/blog/posts_spec.rb b/spec/requests/refinery/blog/posts_spec.rb new file mode 100644 index 0000000..f2c94b0 --- /dev/null +++ b/spec/requests/refinery/blog/posts_spec.rb @@ -0,0 +1,109 @@ +require "spec_helper" + +module Refinery + describe "Blog::Posts" do + login_refinery_user + + context "when has blog posts" do + let!(:blog_post) { FactoryGirl.create(:blog_post, :title => "Refinery CMS blog post") } + + it "should display blog post" do + visit blog_post_path(blog_post) + + page.should have_content(blog_post.title) + end + + it "should display the blog rss feed" do + get blog_rss_feed_path + + response.should be_success + response.content_type.should eq("application/rss+xml") + end + end + + describe "list tagged posts" do + context "when has tagged blog posts" do + before(:each) do + @tag_name = "chicago" + @blog_post = FactoryGirl.create(:blog_post, + :title => "I Love my city", + :tag_list => @tag_name) + @tag = ::Refinery::Blog::Post.tag_counts_on(:tags).first + end + + it "should have one tagged post" do + visit tagged_posts_path(@tag.id, @tag_name.parameterize) + + page.should have_content(@tag_name) + page.should have_content(@blog_post.title) + end + end + end + + describe "#show" do + context "when has no comments" do + let(:blog_post) { FactoryGirl.create(:blog_post) } + + it "should display the blog post" do + visit blog_post_path(blog_post) + + page.should have_content(blog_post.title) + page.should have_content(blog_post.body) + end + end + + context "when has approved comments" do + let(:approved_comment) { FactoryGirl.create(:approved_comment) } + + it "should display the comments" do + visit blog_post_path(approved_comment.post) + + page.should have_content(approved_comment.body) + page.should have_content("Posted by #{approved_comment.name}") + end + end + + context "when has rejected comments" do + let(:rejected_comment) { FactoryGirl.create(:rejected_comment) } + + it "should not display the comments" do + visit blog_post_path(rejected_comment.post) + + page.should_not have_content(rejected_comment.body) + end + end + + context "when has new comments" do + let(:blog_comment) { FactoryGirl.create(:blog_comment) } + + it "should not display the comments" do + visit blog_post_path(blog_comment.post) + + page.should_not have_content(blog_comment.body) + end + end + end + + describe "#show draft preview" do + let(:blog_post) { FactoryGirl.create(:blog_post_draft) } + + context "when logged in as admin" do + it "should display the draft notification" do + visit blog_post_path(blog_post) + + page.should have_content('This page is NOT live for public viewing.') + end + end + + context "when not logged in as an admin" do + before(:each) { visit destroy_refinery_user_session_path } + + it "should not display the blog post" do + visit blog_post_path(blog_post) + + page.should have_content("The page you were looking for doesn't exist (404)") + end + end + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..ea550e2 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,38 @@ +require 'rubygems' + +def load_all(*patterns) + patterns.each { |pattern| Dir[pattern].sort.each { |path| load File.expand_path(path) } } +end + +def setup_environment + # Configure Rails Environment + ENV["RAILS_ENV"] = 'test' + require File.expand_path("../dummy/config/environment.rb", __FILE__) + + require 'rspec/rails' + require 'capybara/rspec' + require 'factory_girl_rails' + + Rails.backtrace_cleaner.remove_silencers! + + RSpec.configure do |config| + config.mock_with :rspec + end +end + +def each_run + FactoryGirl.reload + ActiveSupport::Dependencies.clear + + load_all 'spec/support/**/*.rb' + load_all 'spec/factories/**/*.rb' +end + +# If spork is available in the Gemfile it'll be used but we don't force it. +unless (begin; require 'spork'; rescue LoadError; nil end).nil? + Spork.prefork { setup_environment } + Spork.each_run { each_run } +else + setup_environment + each_run +end diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb new file mode 100644 index 0000000..40acbc9 --- /dev/null +++ b/spec/support/database_cleaner.rb @@ -0,0 +1,17 @@ +require 'database_cleaner' + +RSpec.configure do |config| + config.use_transactional_fixtures = false + + config.before(:suite) do + DatabaseCleaner.strategy = :truncation + end + + config.before(:each) do + DatabaseCleaner.start + end + + config.after(:each) do + DatabaseCleaner.clean + end +end diff --git a/spec/support/devise.rb b/spec/support/devise.rb new file mode 100644 index 0000000..9dc6823 --- /dev/null +++ b/spec/support/devise.rb @@ -0,0 +1,8 @@ +require 'devise' + +RSpec.configure do |config| + config.mock_with :rspec + config.use_transactional_fixtures = false + + config.include Devise::TestHelpers, :type => :controller +end diff --git a/spec/support/refinery.rb b/spec/support/refinery.rb new file mode 100644 index 0000000..d761787 --- /dev/null +++ b/spec/support/refinery.rb @@ -0,0 +1,6 @@ +require 'refinerycms-testing' + +RSpec.configure do |config| + config.extend Refinery::Testing::ControllerMacros::Authentication, :type => :controller + config.extend Refinery::Testing::RequestMacros::Authentication, :type => :request +end |