diff options
author | Philip Arndt <parndt@gmail.com> | 2011-11-09 22:19:07 +1300 |
---|---|---|
committer | Philip Arndt <parndt@gmail.com> | 2011-11-09 22:19:07 +1300 |
commit | 36c005ecd112b76d3c9c2d7092f22d6e06755d73 (patch) | |
tree | 23e37055e6c6aa79a9c5285387052acdc708ba30 /spec/models | |
parent | d18364d359359fa6564ad187d7303f8c167154cd (diff) | |
download | refinerycms-blog-36c005ecd112b76d3c9c2d7092f22d6e06755d73.tar.gz refinerycms-blog-36c005ecd112b76d3c9c2d7092f22d6e06755d73.tar.bz2 refinerycms-blog-36c005ecd112b76d3c9c2d7092f22d6e06755d73.zip |
Refactored everything (models, helpers) into proper namespace of Refinery::Blog. Requires refinery commit 25162b585b9c4023d39fd1a9796140bfa4ecb909
Diffstat (limited to 'spec/models')
-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/models/refinery/blog_category_spec.rb | 42 | ||||
-rw-r--r-- | spec/models/refinery/blog_comment_spec.rb | 22 | ||||
-rw-r--r-- | spec/models/refinery/blog_post_spec.rb | 218 |
6 files changed, 281 insertions, 282 deletions
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/models/refinery/blog_category_spec.rb b/spec/models/refinery/blog_category_spec.rb deleted file mode 100644 index 704b6bb..0000000 --- a/spec/models/refinery/blog_category_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -require 'spec_helper' - -module Refinery - describe BlogCategory do - before(:each) do - @blog_category = FactoryGirl.create(:blog_category) - end - - 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 => @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 << FactoryGirl.create(:blog_post) - end - @blog_category.post_count.should == 2 - end - end - end -end diff --git a/spec/models/refinery/blog_comment_spec.rb b/spec/models/refinery/blog_comment_spec.rb deleted file mode 100644 index 57c90e8..0000000 --- a/spec/models/refinery/blog_comment_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'spec_helper' - -module Refinery - describe BlogComment do - - context "wiring up" do - - before(:each) do - @comment = FactoryGirl.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 -end diff --git a/spec/models/refinery/blog_post_spec.rb b/spec/models/refinery/blog_post_spec.rb deleted file mode 100644 index 15f8593..0000000 --- a/spec/models/refinery/blog_post_spec.rb +++ /dev/null @@ -1,218 +0,0 @@ -require 'spec_helper' - -module Refinery - describe BlogPost do - let(:blog_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 => blog_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 - blog_post.should respond_to(:comments) - end - - it "destroys associated comments" do - FactoryGirl.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 = 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" - 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 = 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 - 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 = 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 - BlogPost.live.count.should be == 2 - BlogPost.live.should == [@blog_post2, @blog_post1] - end - end - - describe "uncategorized scope" do - before do - @uncategorized_blog_post = FactoryGirl.create(:blog_post) - @categorized_blog_post = FactoryGirl.create(:blog_post) - - @categorized_blog_post.categories << FactoryGirl.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 - 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 - BlogPost.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 - BlogPost.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) - 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 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 - BlogPost.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 - BlogPost.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 - BlogPost.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 - BlogPost.teasers_enabled?.should be_false - end - end - - end - - end -end |