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
This commit is contained in:
parent
40be4f71ee
commit
7903bdfed2
14 changed files with 123 additions and 43 deletions
3
Gemfile
3
Gemfile
|
@ -3,11 +3,12 @@ source "http://rubygems.org"
|
||||||
gemspec
|
gemspec
|
||||||
|
|
||||||
## Uncomment the following lines to develop against edge refinery
|
## Uncomment the following lines to develop against edge refinery
|
||||||
gem 'refinerycms', :git => 'git://github.com/resolve/refinerycms.git'
|
gem 'refinerycms', :path => "~/Code/refinerycms" # :git => 'git://github.com/resolve/refinerycms.git'
|
||||||
gem 'awesome_nested_set', :git => 'git://github.com/collectiveidea/awesome_nested_set.git'
|
gem 'awesome_nested_set', :git => 'git://github.com/collectiveidea/awesome_nested_set.git'
|
||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
require 'rbconfig'
|
require 'rbconfig'
|
||||||
|
|
||||||
gem 'sqlite3'
|
gem 'sqlite3'
|
||||||
gem 'mysql2'
|
gem 'mysql2'
|
||||||
gem 'pg'
|
gem 'pg'
|
||||||
|
|
|
@ -40,10 +40,10 @@ module Refinery
|
||||||
end
|
end
|
||||||
|
|
||||||
if Refinery::BlogComment::Moderation.enabled?
|
if Refinery::BlogComment::Moderation.enabled?
|
||||||
flash[:notice] = t('thank_you_moderated', :scope => 'blog.posts.comments')
|
flash[:notice] = t('thank_you_moderated', :scope => 'refinery.blog.posts.comments')
|
||||||
redirect_to main_app.blog_post_url(params[:id])
|
redirect_to main_app.blog_post_url(params[:id])
|
||||||
else
|
else
|
||||||
flash[:notice] = t('thank_you', :scope => 'blog.posts.comments')
|
flash[:notice] = t('thank_you', :scope => 'refinery.blog.posts.comments')
|
||||||
redirect_to main_app.blog_post_url(params[:id],
|
redirect_to main_app.blog_post_url(params[:id],
|
||||||
:anchor => "comment-#{@blog_comment.to_param}")
|
:anchor => "comment-#{@blog_comment.to_param}")
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
<%= simple_format auto_link(comment.message.to_s) %>
|
<%= simple_format auto_link(comment.message.to_s) %>
|
||||||
<footer class='blog_comment_author'>
|
<footer class='blog_comment_author'>
|
||||||
<p>
|
<p>
|
||||||
<%= t('by', :scope => 'blog.posts.comments', :who => comment.name) %>,
|
<%= t('by', :scope => 'refinery.blog.posts.comments', :who => comment.name) %>,
|
||||||
<%= t('time_ago', :scope => 'blog.posts.comments', :time => time_ago_in_words(comment.created_at)) %>
|
<%= t('time_ago', :scope => 'refinery.blog.posts.comments', :time => time_ago_in_words(comment.created_at)) %>
|
||||||
</p>
|
</p>
|
||||||
</footer>
|
</footer>
|
||||||
</article>
|
</article>
|
||||||
|
|
|
@ -24,6 +24,7 @@ Gem::Specification.new do |s|
|
||||||
s.add_dependency 'filters_spam', '~> 0.2'
|
s.add_dependency 'filters_spam', '~> 0.2'
|
||||||
s.add_dependency 'acts-as-taggable-on'
|
s.add_dependency 'acts-as-taggable-on'
|
||||||
s.add_dependency 'seo_meta', '~> 1.2.0.rc1'
|
s.add_dependency 'seo_meta', '~> 1.2.0.rc1'
|
||||||
|
s.add_dependency 'rails_autolink'
|
||||||
|
|
||||||
# Development dependencies
|
# Development dependencies
|
||||||
s.add_development_dependency 'refinerycms-testing', '~> 2.0.0'
|
s.add_development_dependency 'refinerycms-testing', '~> 2.0.0'
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
module Refinery
|
module Refinery
|
||||||
module Blog
|
module Blog
|
||||||
class Engine < Rails::Engine
|
class Engine < Rails::Engine
|
||||||
|
require 'rails_autolink'
|
||||||
|
|
||||||
config.to_prepare do
|
config.to_prepare do
|
||||||
require 'refinery/blog/tabs'
|
require 'refinery/blog/tabs'
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@ Gem::Specification.new do |s|
|
||||||
s.name = %q{refinerycms-blog}
|
s.name = %q{refinerycms-blog}
|
||||||
s.version = %q{2.0.0}
|
s.version = %q{2.0.0}
|
||||||
s.description = %q{A really straightforward open source Ruby on Rails blog engine designed for integration with RefineryCMS.}
|
s.description = %q{A really straightforward open source Ruby on Rails blog engine designed for integration with RefineryCMS.}
|
||||||
s.date = %q{2011-08-18}
|
s.date = %q{2011-09-04}
|
||||||
s.summary = %q{Ruby on Rails blogging engine for RefineryCMS.}
|
s.summary = %q{Ruby on Rails blogging engine for RefineryCMS.}
|
||||||
s.email = %q{info@refinerycms.com}
|
s.email = %q{info@refinerycms.com}
|
||||||
s.homepage = %q{http://refinerycms.com/blog}
|
s.homepage = %q{http://refinerycms.com/blog}
|
||||||
|
@ -14,9 +14,10 @@ Gem::Specification.new do |s|
|
||||||
|
|
||||||
# Runtime dependencies
|
# Runtime dependencies
|
||||||
s.add_dependency 'refinerycms-core', '~> 2.0.0'
|
s.add_dependency 'refinerycms-core', '~> 2.0.0'
|
||||||
s.add_dependency 'refinerycms-pages', '~> 2.0.0'
|
|
||||||
s.add_dependency 'filters_spam', '~> 0.2'
|
s.add_dependency 'filters_spam', '~> 0.2'
|
||||||
s.add_dependency 'acts-as-taggable-on'
|
s.add_dependency 'acts-as-taggable-on'
|
||||||
|
s.add_dependency 'seo_meta', '~> 1.2.0.rc1'
|
||||||
|
s.add_dependency 'rails_autolink'
|
||||||
|
|
||||||
# Development dependencies
|
# Development dependencies
|
||||||
s.add_development_dependency 'refinerycms-testing', '~> 2.0.0'
|
s.add_development_dependency 'refinerycms-testing', '~> 2.0.0'
|
||||||
|
@ -99,6 +100,9 @@ Gem::Specification.new do |s|
|
||||||
app/models/refinery/blog_comment.rb
|
app/models/refinery/blog_comment.rb
|
||||||
app/models/refinery/blog_post.rb
|
app/models/refinery/blog_post.rb
|
||||||
app/models/refinery/categorization.rb
|
app/models/refinery/categorization.rb
|
||||||
|
app/sweepers
|
||||||
|
app/sweepers/refinery
|
||||||
|
app/sweepers/refinery/blog_sweeper.rb
|
||||||
app/views
|
app/views
|
||||||
app/views/refinery
|
app/views/refinery
|
||||||
app/views/refinery/admin
|
app/views/refinery/admin
|
||||||
|
@ -204,6 +208,10 @@ Gem::Specification.new do |s|
|
||||||
script
|
script
|
||||||
script/rails
|
script/rails
|
||||||
spec
|
spec
|
||||||
|
spec/factories
|
||||||
|
spec/factories/blog_categories.rb
|
||||||
|
spec/factories/blog_comments.rb
|
||||||
|
spec/factories/blog_posts.rb
|
||||||
spec/models
|
spec/models
|
||||||
spec/models/refinery
|
spec/models/refinery
|
||||||
spec/models/refinery/blog_category_spec.rb
|
spec/models/refinery/blog_category_spec.rb
|
||||||
|
@ -211,17 +219,18 @@ Gem::Specification.new do |s|
|
||||||
spec/models/refinery/blog_post_spec.rb
|
spec/models/refinery/blog_post_spec.rb
|
||||||
spec/rcov.opts
|
spec/rcov.opts
|
||||||
spec/requests
|
spec/requests
|
||||||
spec/requests/blog_categories_spec.rb
|
spec/requests/refinery
|
||||||
spec/requests/blog_posts_spec.rb
|
spec/requests/refinery/admin
|
||||||
spec/requests/manage_blog_posts_spec.rb
|
spec/requests/refinery/admin/blog
|
||||||
|
spec/requests/refinery/admin/blog/comments_spec.rb
|
||||||
|
spec/requests/refinery/admin/blog/posts_spec.rb
|
||||||
|
spec/requests/refinery/blog
|
||||||
|
spec/requests/refinery/blog/categories_spec.rb
|
||||||
|
spec/requests/refinery/blog/posts_spec.rb
|
||||||
spec/spec_helper.rb
|
spec/spec_helper.rb
|
||||||
spec/support
|
spec/support
|
||||||
spec/support/database_cleaner.rb
|
spec/support/database_cleaner.rb
|
||||||
spec/support/devise.rb
|
spec/support/devise.rb
|
||||||
spec/support/factories
|
|
||||||
spec/support/factories/blog_categories.rb
|
|
||||||
spec/support/factories/blog_comments.rb
|
|
||||||
spec/support/factories/blog_posts.rb
|
|
||||||
spec/support/refinery.rb
|
spec/support/refinery.rb
|
||||||
todo.md
|
todo.md
|
||||||
)
|
)
|
||||||
|
|
2
spec/dummy/.gitignore
vendored
2
spec/dummy/.gitignore
vendored
|
@ -31,6 +31,8 @@ public/themes/*
|
||||||
# Public Cache
|
# Public Cache
|
||||||
public/javascripts/cache
|
public/javascripts/cache
|
||||||
public/stylesheets/cache
|
public/stylesheets/cache
|
||||||
|
public/*.html
|
||||||
|
public/refinery/cache
|
||||||
|
|
||||||
# Vendor Cache
|
# Vendor Cache
|
||||||
vendor/cache
|
vendor/cache
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :blog_category, :class => 'refinery/blog_category' do
|
factory :blog_category, :class => Refinery::BlogCategory do
|
||||||
sequence(:title) { |n| "Shopping #{n}" }
|
sequence(:title) { |n| "Shopping #{n}" }
|
||||||
end
|
end
|
||||||
end
|
end
|
19
spec/factories/blog_comments.rb
Normal file
19
spec/factories/blog_comments.rb
Normal file
|
@ -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
|
|
@ -1,5 +1,5 @@
|
||||||
FactoryGirl.define do
|
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" }
|
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."
|
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
|
draft false
|
|
@ -5,36 +5,83 @@ module Refinery
|
||||||
login_refinery_user
|
login_refinery_user
|
||||||
|
|
||||||
context "when has blog posts" do
|
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
|
it "should display blog post" do
|
||||||
visit blog_post_path(blog_post)
|
visit blog_post_path(blog_post)
|
||||||
page.should have_content("Refinery CMS blog post")
|
|
||||||
|
page.should have_content(blog_post.title)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should display the blog rss feed" do
|
it "should display the blog rss feed" do
|
||||||
get blog_rss_feed_path
|
get blog_rss_feed_path
|
||||||
|
|
||||||
response.should be_success
|
response.should be_success
|
||||||
response.content_type.should eq("application/rss+xml")
|
response.content_type.should eq("application/rss+xml")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "list tagged posts" do
|
describe "list tagged posts" do
|
||||||
context "when has tagged blog posts" do
|
context "when has tagged blog posts" do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@tag_name = "chicago"
|
@tag_name = "chicago"
|
||||||
@blog_post = FactoryGirl.create(:blog_post,
|
@blog_post = FactoryGirl.create(:blog_post,
|
||||||
:title => "I Love my city",
|
:title => "I Love my city",
|
||||||
:tag_list => @tag_name)
|
:tag_list => @tag_name)
|
||||||
tag = ::Refinery::BlogPost.tag_counts_on(:tags).first
|
@tag = ::Refinery::BlogPost.tag_counts_on(:tags).first
|
||||||
visit tagged_posts_path(tag.id, @tag_name.parameterize)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should have one tagged post" do
|
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(@tag_name)
|
||||||
page.should have_content(@blog_post.title)
|
page.should have_content(@blog_post.title)
|
||||||
end
|
end
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,34 +6,39 @@ def setup_environment
|
||||||
# need to restart spork for it take effect.
|
# need to restart spork for it take effect.
|
||||||
|
|
||||||
# Configure Rails Environment
|
# Configure Rails Environment
|
||||||
ENV["RAILS_ENV"] ||= 'test'
|
ENV["RAILS_ENV"] = 'test'
|
||||||
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
||||||
|
|
||||||
require 'rspec/rails'
|
require 'rspec/rails'
|
||||||
require 'capybara/rspec'
|
require 'capybara/rspec'
|
||||||
require 'factory_girl'
|
|
||||||
require 'refinerycms-testing'
|
|
||||||
|
|
||||||
Rails.backtrace_cleaner.remove_silencers!
|
Rails.backtrace_cleaner.remove_silencers!
|
||||||
|
|
||||||
|
RSpec.configure do |config|
|
||||||
|
config.mock_with :rspec
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
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[
|
Dir[
|
||||||
File.expand_path("../support/**/*.rb", __FILE__),
|
File.expand_path("../support/**/*.rb", __FILE__),
|
||||||
File.expand_path("../factories/**/*.rb", __FILE__)
|
File.expand_path("../factories/**/*.rb", __FILE__)
|
||||||
].each {|f| require f}
|
].each {|f| require f}
|
||||||
|
|
||||||
RSpec.configure do |config|
|
|
||||||
config.mock_with :rspec
|
|
||||||
config.use_transactional_fixtures = false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def each_run
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# If spork is available in the Gemfile it'll be used but we don't force it.
|
# 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?
|
unless (begin; require 'spork'; rescue LoadError; nil end).nil?
|
||||||
Spork.prefork do
|
Spork.prefork do
|
||||||
setup_environment
|
setup_environment
|
||||||
|
|
||||||
|
ActiveSupport::Dependencies.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
Spork.each_run do
|
Spork.each_run do
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
require 'database_cleaner'
|
require 'database_cleaner'
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
|
config.use_transactional_fixtures = false
|
||||||
|
|
||||||
config.before(:suite) do
|
config.before(:suite) do
|
||||||
DatabaseCleaner.strategy = :truncation
|
DatabaseCleaner.strategy = :truncation
|
||||||
end
|
end
|
||||||
|
|
|
@ -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
|
|
Loading…
Add table
Add a link
Reference in a new issue