solve a bug when creating new content instance + fix rspec tests for ruby 1.9.2

This commit is contained in:
did 2011-04-28 23:47:01 +02:00
parent 820d55a83c
commit 77ea45c98b
7 changed files with 117 additions and 76 deletions

View File

@ -24,6 +24,7 @@ class ContentInstance
after_create :send_notifications
## named scopes ##
scope :persisted, where(:updated_at.ne => nil)
scope :latest_updated, :order_by => :updated_at.desc, :limit => Locomotive.config.lastest_items_nb
## methods ##

View File

@ -15,7 +15,7 @@
.inner
%h2!= t('admin.contents.index.lastest_items')
%ul
- content_type.contents.latest_updated.each do |content|
- content_type.contents.persisted.latest_updated.each do |content|
%li
= link_to truncate(content.send(content_type.highlighted_field_name).to_s, :length => 20), edit_admin_content_path(content_type.slug, content)
%span= time_ago_in_words(content.updated_at)

View File

@ -17,9 +17,10 @@ describe 'Bushido support' do
end
it 'does not add instance methods to Site' do
Site.instance_methods.include?('add_bushido_domains').should be_false
Site.instance_methods.include?('remove_bushido_domains').should be_false
Site.methods.include?('create_first_one_with_bushido').should be_false
Site.should_not include_instance_method :add_bushido_domains
Site.should_not include_instance_method :remove_bushido_domains
Site.should_not include_class_method :create_first_one_with_bushido
end
end
@ -37,8 +38,8 @@ describe 'Bushido support' do
end
it 'does not add methods to Site' do
Site.instance_methods.include?('add_bushido_domains').should be_false
Site.instance_methods.include?('remove_bushido_domains').should be_false
Site.should_not include_instance_method :add_bushido_domains
Site.should_not include_instance_method :remove_bushido_domains
end
end
@ -53,7 +54,7 @@ describe 'Bushido support' do
it 'adds a method to automatically create a site with Bushido settings' do
configure_locomotive_with_bushido
Site.methods.include?('create_first_one_with_bushido').should be_true
Site.should include_class_method :create_first_one_with_bushido
end
it 'tells bushido is enabled when forcing it' do

View File

@ -18,9 +18,10 @@ describe 'Heroku support' do
end
it 'does not add instance methods to Site' do
Site.instance_methods.include?('add_heroku_domains').should be_false
Site.instance_methods.include?('remove_heroku_domains').should be_false
Site.methods.include?('create_first_one_with_heroku').should be_false
Site.should_not include_instance_method :add_heroku_domains
Site.should_not include_instance_method :remove_heroku_domains
Site.should_not include_class_method :create_first_one_with_heroku
end
end
@ -42,8 +43,8 @@ describe 'Heroku support' do
end
it 'does not add methods to Site' do
Site.instance_methods.include?('add_heroku_domains').should be_false
Site.instance_methods.include?('remove_heroku_domains').should be_false
Site.should_not include_instance_method :add_heroku_domains
Site.should_not include_instance_method :remove_heroku_domains
end
end
@ -58,7 +59,7 @@ describe 'Heroku support' do
it 'adds a method to automatically create a site with Heroku settings' do
configure_locomotive_with_heroku
Site.methods.include?('create_first_one_with_heroku').should be_true
Site.should include_class_method :create_first_one_with_heroku
end
it 'tells heroku is enabled when forcing it' do

View File

@ -10,6 +10,9 @@ Dir[Rails.root.join('spec/support/**/*.rb')].each {|f| require f}
Locomotive.configure_for_test
RSpec.configure do |config|
config.include(Locomotive::RSpec::Matchers)
# == Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
@ -43,35 +46,3 @@ RSpec.configure do |config|
end
end
end
# # This file is copied to ~/spec when you run 'ruby script/generate rspec'
# # from the project root directory.
# ENV["RAILS_ENV"] ||= 'test'
# require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
# require 'rspec/rails'
#
# # Requires supporting files with custom matchers and macros, etc,
# # in ./support/ and its subdirectories.
# Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
#
# Rspec.configure do |config|
# config.expect_with :rspec
# config.mock_with :mocha
#
# config.before(:each) do
# Locomotive.config.heroku = false
# end
#
# require 'database_cleaner'
# config.before(:suite) do
# DatabaseCleaner.strategy = :truncation
# DatabaseCleaner.orm = "mongoid"
# end
#
# config.before(:each) do
# if self.described_class != Locomotive::Import::Job
# DatabaseCleaner.clean
# end
# end
# end

View File

@ -1,31 +0,0 @@
module Spec
module Rails
module Matchers
class BeValid #:nodoc:
def matches?(model)
@model = model
@model.errors.clear
@model.errors.empty? && @model.valid?
end
def failure_message
"#{@model.class} expected to be valid but had errors:\n #{@model.errors.full_messages.join("\n ")}"
end
def negative_failure_message
"#{@model.class} expected to be invalid but was valid.\n"
end
def description
"be valid"
end
end
def be_valid
BeValid.new
end
end
end
end

98
spec/support/matchers.rb Normal file
View File

@ -0,0 +1,98 @@
module Locomotive
module RSpec
module Matchers
class BeValid #:nodoc:
def matches?(model)
@model = model
@model.errors.clear
@model.errors.empty? && @model.valid?
end
def failure_message
"#{@model.class} expected to be valid but had errors:\n #{@model.errors.full_messages.join("\n ")}"
end
def negative_failure_message
"#{@model.class} expected to be invalid but was valid.\n"
end
def description
"be valid"
end
end
def be_valid
BeValid.new
end
class IncludeInstanceMethod #:nodoc:
def initialize(meth)
@meth = meth
end
def matches?(klass)
@klass = klass
if RUBY_VERSION =~ /1\.9/
klass.instance_methods.include?(@meth.to_sym) == true
else
klass.instance_methods.include?(@meth.to_s) == true
end
end
def failure_message
"#{@klass} expected to include the instance method #{@meth}"
end
def negative_failure_message
"#{@klass} expected to not include the instance method #{@meth} but included it.\n"
end
def description
"include instance method #{@meth}"
end
end
def include_instance_method(meth)
IncludeInstanceMethod.new(meth)
end
class IncludeClassMethod #:nodoc:
def initialize(meth)
@meth = meth
end
def matches?(klass)
@klass = klass
if RUBY_VERSION =~ /1\.9/
klass.methods.include?(@meth.to_sym) == true
else
klass.methods.include?(@meth.to_s) == true
end
end
def failure_message
"#{@klass} expected to include the class method #{@meth}"
end
def negative_failure_message
"#{@klass} expected to not include the class method #{@meth} but included it.\n"
end
def description
"include class method #{@meth}"
end
end
def include_class_method(meth)
IncludeClassMethod.new(meth)
end
end
end
end