Skip to content
This repository
Browse code

run specs for active_support 3.2, some specs fixed

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

0 notes on commit babd229

Please sign in to comment.
Something went wrong with that request. Please try again.