Browse files

run specs for active_support 3.2, some specs fixed

  • Loading branch information...
1 parent 230dfc7 commit babd229f674b41b04d84eadcbf0b22784f97a875 @langalex committed Jan 29, 2012
View
4 Rakefile
@@ -25,7 +25,7 @@ task :spec do
Rake::Task[:spec_unit].execute
Rake::Task[:spec_functional].execute
else
- ['3_0', '3_1'].each do |version|
+ ['3_0', '3_1', '3_2'].each do |version|
Bundler.with_clean_env do
ENV['BUNDLE_GEMFILE'] = "active_support_#{version}"
sh "bundle install"
@@ -34,7 +34,7 @@ task :spec do
end
end
end
-
+
end
desc 'Generate documentation'
View
4 active_support_3_2
@@ -0,0 +1,4 @@
+source :rubygems
+
+gem 'activemodel', '~>3.2'
+gemspec
View
51 active_support_3_2.lock
@@ -0,0 +1,51 @@
+PATH
+ remote: .
+ specs:
+ couch_potato (0.6.0)
+ activemodel
+ couchrest (>= 1.0.1)
+ json (~> 1.6.0)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activemodel (3.2.1)
+ activesupport (= 3.2.1)
+ builder (~> 3.0.0)
+ activesupport (3.2.1)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ builder (3.0.0)
+ couchrest (1.1.2)
+ mime-types (~> 1.15)
+ multi_json (~> 1.0.0)
+ rest-client (~> 1.6.1)
+ diff-lcs (1.1.3)
+ i18n (0.6.0)
+ json (1.6.5)
+ mime-types (1.17.2)
+ multi_json (1.0.4)
+ rake (0.9.2.2)
+ rest-client (1.6.7)
+ mime-types (>= 1.16)
+ rspec (2.8.0)
+ rspec-core (~> 2.8.0)
+ rspec-expectations (~> 2.8.0)
+ rspec-mocks (~> 2.8.0)
+ rspec-core (2.8.0)
+ rspec-expectations (2.8.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.8.0)
+ timecop (0.3.5)
+ tzinfo (0.3.31)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ activemodel (~> 3.2)
+ couch_potato!
+ rake
+ rspec (>= 2.0)
+ timecop
+ tzinfo
View
8 lib/couch_potato/persistence/active_model_compliance.rb
@@ -12,14 +12,18 @@ def to_model
self
end
+ def to_partial_path
+ "#{self.class.name.underscore.pluralize}/#{self.class.name.underscore}"
+ end
+
def errors
super || {}
end
-
+
def persisted?
!self.new?
end
-
+
def to_key
persisted? ? [to_param] : nil
end
View
33 lib/couch_potato/persistence/dirty_attributes.rb
@@ -2,45 +2,37 @@
module CouchPotato
module Persistence
module DirtyAttributes
-
+
def self.included(base) #:nodoc:
base.send :include, ActiveModel::Dirty
base.class_eval do
+ extend ClassMethods
after_save :reset_dirty_attributes
end
end
-
+
def initialize(attributes = {})
super
end
-
+
# returns true if a model has dirty attributes, i.e. their value has changed since the last save
- def dirty?
+ def dirty?
changed? || @forced_dirty
end
-
+
# marks a model as dirty
def is_dirty
@forced_dirty = true
end
-
- def method_missing(name, *args)
- if(name.to_s.include?('_will_change!'))
- self.class.define_attribute_methods self.class.property_names
- send(name, *args)
- else
- super
- end
- end
-
+
private
-
+
def reset_dirty_attributes
@previously_changed = changes
@changed_attributes.clear
@forced_dirty = nil
end
-
+
def clone_attribute(value)
if [Fixnum, Symbol, TrueClass, FalseClass, NilClass, Float, BigDecimal].include?(value.class)
value
@@ -51,6 +43,13 @@ def clone_attribute(value)
value.clone
end
end
+
+ module ClassMethods
+ def property(name, *args)
+ super name, *args
+ define_attribute_methods [name]
+ end
+ end
end
end
end
View
18 lib/couch_potato/persistence/properties.rb
@@ -5,33 +5,33 @@ module Persistence
module Properties
class PropertyList
include Enumerable
-
+
attr_accessor :list
-
+
def initialize(clazz)
@clazz = clazz
@list = []
end
-
+
def each
(list + inherited_properties).each {|property| yield property}
end
-
+
def <<(property)
@list << property
end
-
+
def inherited_properties
superclazz = @clazz.superclass
properties = []
- while superclazz && superclazz.respond_to?(:properties)
+ while superclazz && superclazz.is_a?(PropertyList)
properties << superclazz.properties.list
superclazz = superclazz.superclass
end
properties.flatten
end
end
-
+
def self.included(base) #:nodoc:
base.extend ClassMethods
base.class_eval do
@@ -41,11 +41,11 @@ def self.properties
end
end
end
-
+
def type_caster #:nodoc:
@type_caster ||= TypeCaster.new
end
-
+
module ClassMethods
# returns all the property names of a model class that have been defined using the #property method
#
View
2 lib/couch_potato/persistence/simple_property.rb
@@ -52,8 +52,6 @@ def accessors_module_for(clazz)
def define_accessors(base, name, options)
base.class_eval do
- include PropertyMethods
-
define_method "#{name}" do
load_attribute_from_document(name) unless instance_variable_defined?("@#{name}")
value = instance_variable_get("@#{name}")
View
28 spec/unit/active_model_compliance_spec.rb
@@ -2,7 +2,7 @@
begin
require 'active_model'
-
+
describe 'ActiveModel conformance of couch potato objects' do
include ActiveModel::Lint::Tests
@@ -23,47 +23,53 @@ class ActiveComment
before(:each) do
@model = ActiveComment.new
end
-
+
+ describe '#to_partial_path' do
+ it 'returns a path based on the class name' do
+ @model.to_partial_path.should == 'active_comments/active_comment'
+ end
+ end
+
describe "#persisted?" do
it "should return false if it is a new document " do
@model.should_not be_persisted
end
-
+
it "should be true if it was saved" do
@comment = ActiveComment.new(:name => 'Thilo', :email => 'test@local.host')
CouchPotato.database.save_document! @comment
@comment.should be_persisted
end
end
-
+
describe "#to_key" do
it "should return nil if the document was not persisted" do
@model.to_key.should be_nil
end
-
+
it "should return the id of the document if it was persisted" do
@comment = ActiveComment.new(:name => 'Thilo', :email => 'test@local.host')
CouchPotato.database.save_document! @comment
@comment.to_key.should == [@comment.id]
end
end
-
-
+
+
describe "#errors" do
it "should return a single error as array" do
@model.valid?
@model.errors[:name].should be_kind_of(Array)
end
-
+
it "should return multiple errors as array" do
@model.valid?
@model.errors[:email].size.should == 2
end
-
+
it "should return no error as an empty array" do
@model.errors[:name].should == []
end
-
+
it "should be able to be Marshal.dump'ed" do
lambda { Marshal.dump(@model.errors) }.should_not raise_error
end
@@ -88,7 +94,7 @@ def assert_kind_of(klass, object)
object.should be_a(klass)
end
end
-
+
rescue LoadError
STDERR.puts "WARNING: active_model gem not installed. Not running ActiveModel specs."
end

0 comments on commit babd229

Please sign in to comment.