diff options
author | Jamie Winsor <jamie@enmasse.com> | 2011-09-04 03:20:51 -0700 |
---|---|---|
committer | Jamie Winsor <jamie@enmasse.com> | 2011-09-04 14:35:03 -0700 |
commit | 7903bdfed26f085f6d07d104ac458bc4319b1e32 (patch) | |
tree | fd950e2c1d1d234e0e6a590d24296a4a396798a3 /spec | |
parent | 40be4f71ee425ee55ecedea96ff2b0dc510d71db (diff) | |
download | refinerycms-blog-7903bdfed26f085f6d07d104ac458bc4319b1e32.tar.gz refinerycms-blog-7903bdfed26f085f6d07d104ac458bc4319b1e32.tar.bz2 refinerycms-blog-7903bdfed26f085f6d07d104ac458bc4319b1e32.zip |
refactor factories and add #show tests for posts controller
Do not want to cache classes, but do want to reload models after factory girl:
http://groups.google.com/group/factory_girl/browse_thread/thread/daa24556d90c31fc
http://stackoverflow.com/questions/5145165/associationtypemismatch-and-factorygirl
rails_autolink was removed from Rails 3.1 and abstracted to an external gem
fix display author name and post time on comment show
fix namespace for thanking and moderated flash notices
Diffstat (limited to 'spec')
-rw-r--r-- | spec/dummy/.gitignore | 2 | ||||
-rw-r--r-- | spec/factories/blog_categories.rb (renamed from spec/support/factories/blog_categories.rb) | 2 | ||||
-rw-r--r-- | spec/factories/blog_comments.rb | 19 | ||||
-rw-r--r-- | spec/factories/blog_posts.rb (renamed from spec/support/factories/blog_posts.rb) | 2 | ||||
-rw-r--r-- | spec/requests/refinery/blog/posts_spec.rb | 61 | ||||
-rw-r--r-- | spec/spec_helper.rb | 27 | ||||
-rw-r--r-- | spec/support/database_cleaner.rb | 2 | ||||
-rw-r--r-- | spec/support/factories/blog_comments.rb | 8 |
8 files changed, 95 insertions, 28 deletions
diff --git a/spec/dummy/.gitignore b/spec/dummy/.gitignore index d80f252..c698a36 100644 --- a/spec/dummy/.gitignore +++ b/spec/dummy/.gitignore @@ -31,6 +31,8 @@ public/themes/* # Public Cache public/javascripts/cache public/stylesheets/cache +public/*.html +public/refinery/cache # Vendor Cache vendor/cache diff --git a/spec/support/factories/blog_categories.rb b/spec/factories/blog_categories.rb index 31ec28b..9ee4f16 100644 --- a/spec/support/factories/blog_categories.rb +++ b/spec/factories/blog_categories.rb @@ -1,5 +1,5 @@ FactoryGirl.define do - factory :blog_category, :class => 'refinery/blog_category' do + factory :blog_category, :class => Refinery::BlogCategory 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..9818c07 --- /dev/null +++ b/spec/factories/blog_comments.rb @@ -0,0 +1,19 @@ +FactoryGirl.define do + factory :blog_comment, :class => Refinery::BlogComment 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/support/factories/blog_posts.rb b/spec/factories/blog_posts.rb index 4586b36..0b8b888 100644 --- a/spec/support/factories/blog_posts.rb +++ b/spec/factories/blog_posts.rb @@ -1,5 +1,5 @@ FactoryGirl.define do - factory :blog_post, :class => 'refinery/blog_post' do + factory :blog_post, :class => Refinery::BlogPost 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 diff --git a/spec/requests/refinery/blog/posts_spec.rb b/spec/requests/refinery/blog/posts_spec.rb index eba6131..4017d03 100644 --- a/spec/requests/refinery/blog/posts_spec.rb +++ b/spec/requests/refinery/blog/posts_spec.rb @@ -5,36 +5,83 @@ module Refinery login_refinery_user context "when has blog posts" do - let(:blog_post) { FactoryGirl.create(:blog_post, :title => "Refinery CMS blog post") } + 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("Refinery CMS 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::BlogPost.tag_counts_on(:tags).first - visit tagged_posts_path(tag.id, @tag_name.parameterize) + :title => "I Love my city", + :tag_list => @tag_name) + @tag = ::Refinery::BlogPost.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 end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a3fe107..b8df592 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,34 +6,39 @@ def setup_environment # need to restart spork for it take effect. # Configure Rails Environment - ENV["RAILS_ENV"] ||= 'test' + ENV["RAILS_ENV"] = 'test' require File.expand_path("../dummy/config/environment.rb", __FILE__) require 'rspec/rails' require 'capybara/rspec' - require 'factory_girl' - require 'refinerycms-testing' - + Rails.backtrace_cleaner.remove_silencers! - Dir[ - File.expand_path("../support/**/*.rb", __FILE__), - File.expand_path("../factories/**/*.rb", __FILE__) - ].each {|f| require f} - RSpec.configure do |config| config.mock_with :rspec - config.use_transactional_fixtures = false end end -def each_run +def each_run + require 'factory_girl_rails' + require 'refinerycms-testing' + + Dir[File.expand_path("../../app/models/**/*.rb", __FILE__)].each do |model| + load model + end + + Dir[ + File.expand_path("../support/**/*.rb", __FILE__), + File.expand_path("../factories/**/*.rb", __FILE__) + ].each {|f| require f} 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 do setup_environment + + ActiveSupport::Dependencies.clear end Spork.each_run do diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb index a104c53..40acbc9 100644 --- a/spec/support/database_cleaner.rb +++ b/spec/support/database_cleaner.rb @@ -1,6 +1,8 @@ require 'database_cleaner' RSpec.configure do |config| + config.use_transactional_fixtures = false + config.before(:suite) do DatabaseCleaner.strategy = :truncation end diff --git a/spec/support/factories/blog_comments.rb b/spec/support/factories/blog_comments.rb deleted file mode 100644 index 0bb5206..0000000 --- a/spec/support/factories/blog_comments.rb +++ /dev/null @@ -1,8 +0,0 @@ -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 - end -end |