mongomodel 0.4.8 → 0.4.9

Sign up to get free protection for your applications and to get access to all the features.
data/Appraisals CHANGED
@@ -1,26 +1,46 @@
1
+ RAILS_3_1 = "3.1.10"
2
+ RAILS_3_2 = "3.2.11"
3
+
1
4
  appraise "rails-3.1" do
2
- gem "activesupport", "3.1.8"
3
- gem "activemodel", "3.1.8"
5
+ gem "activesupport", RAILS_3_1
6
+ gem "activemodel", RAILS_3_1
4
7
  end
5
8
 
6
9
  appraise "rails-3.2" do
7
- gem "activesupport", "3.2.8"
8
- gem "activemodel", "3.2.8"
10
+ gem "activesupport", RAILS_3_2
11
+ gem "activemodel", RAILS_3_2
9
12
  end
10
13
 
11
- appraise "rails-4" do
12
- gem "activesupport", :git => "https://github.com/rails/rails.git"
13
- gem "activemodel", :git => "https://github.com/rails/rails.git"
14
- end
14
+ if RUBY_VERSION >= "1.9"
15
+ appraise "rails-4" do
16
+ gem "activesupport", :git => "https://github.com/rails/rails.git"
17
+ gem "activemodel", :git => "https://github.com/rails/rails.git"
18
+ gem "journey", :git => "https://github.com/rails/journey.git"
19
+ end
20
+
21
+ appraise "rails-4-protected-attributes" do
22
+ gem "activesupport", :git => "https://github.com/rails/rails.git"
23
+ gem "activemodel", :git => "https://github.com/rails/rails.git"
24
+ gem "protected_attributes", :git=>"https://github.com/rails/protected_attributes.git"
25
+ gem "journey", :git => "https://github.com/rails/journey.git"
26
+ end
27
+
28
+ appraise "rails-4-observers" do
29
+ gem "activesupport", :git => "https://github.com/rails/rails.git"
30
+ gem "activemodel", :git => "https://github.com/rails/rails.git"
31
+ gem "rails-observers", :git => "https://github.com/rails/rails-observers.git"
32
+ gem "journey", :git => "https://github.com/rails/journey.git"
33
+ end
15
34
 
16
- appraise "mongoid" do
17
- gem "mongoid"
18
- gem "activesupport", "3.2.8"
19
- gem "activemodel", "3.2.8"
35
+ appraise "mongoid" do
36
+ gem "mongoid"
37
+ gem "activesupport", RAILS_3_2
38
+ gem "activemodel", RAILS_3_2
39
+ end
20
40
  end
21
41
 
22
42
  appraise "mongo_mapper" do
23
43
  gem "mongo_mapper"
24
- gem "activesupport", "3.2.8"
25
- gem "activemodel", "3.2.8"
44
+ gem "activesupport", RAILS_3_2
45
+ gem "activemodel", RAILS_3_2
26
46
  end
data/Gemfile CHANGED
@@ -3,5 +3,5 @@ source "http://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem "appraisal", "~> 0.3.6"
6
- gem "bson_ext", "~> 1.5"
6
+ gem "bson_ext", "~> 1.8"
7
7
  gem "tzinfo"
@@ -3,15 +3,16 @@
3
3
  puts "Loading MongoModel sandbox..."
4
4
 
5
5
  require "rubygems"
6
- require "bundler/setup"
7
- Bundler.require
8
-
9
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
6
+ require "bundler"
7
+ Bundler.setup
10
8
 
11
9
  require 'irb'
12
10
  require 'irb/completion'
13
11
 
14
- MongoModel.logger = ActiveSupport::BufferedLogger.new(STDERR)
12
+ require "mongomodel"
13
+
14
+ logger = defined?(ActiveSupport::Logger) ? ActiveSupport::Logger : ActiveSupport::BufferedLogger
15
+ MongoModel.logger = logger.new(STDERR)
15
16
 
16
17
  IRB.setup(nil)
17
18
 
@@ -3,10 +3,10 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "appraisal", "~> 0.3.6"
6
- gem "bson_ext", "~> 1.5"
6
+ gem "bson_ext", "~> 1.8"
7
7
  gem "tzinfo"
8
8
  gem "mongo_mapper"
9
- gem "activesupport", "3.2.8"
10
- gem "activemodel", "3.2.8"
9
+ gem "activesupport", "3.2.11"
10
+ gem "activemodel", "3.2.11"
11
11
 
12
12
  gemspec :path=>"../"
@@ -3,10 +3,10 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "appraisal", "~> 0.3.6"
6
- gem "bson_ext", "~> 1.5"
6
+ gem "bson_ext", "~> 1.8"
7
7
  gem "tzinfo"
8
8
  gem "mongoid"
9
- gem "activesupport", "3.2.8"
10
- gem "activemodel", "3.2.8"
9
+ gem "activesupport", "3.2.11"
10
+ gem "activemodel", "3.2.11"
11
11
 
12
12
  gemspec :path=>"../"
@@ -3,9 +3,9 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "appraisal", "~> 0.3.6"
6
- gem "bson_ext", "~> 1.5"
6
+ gem "bson_ext", "~> 1.8"
7
7
  gem "tzinfo"
8
- gem "activesupport", "3.1.8"
9
- gem "activemodel", "3.1.8"
8
+ gem "activesupport", "3.1.10"
9
+ gem "activemodel", "3.1.10"
10
10
 
11
11
  gemspec :path=>"../"
@@ -3,9 +3,9 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "appraisal", "~> 0.3.6"
6
- gem "bson_ext", "~> 1.5"
6
+ gem "bson_ext", "~> 1.8"
7
7
  gem "tzinfo"
8
- gem "activesupport", "3.2.8"
9
- gem "activemodel", "3.2.8"
8
+ gem "activesupport", "3.2.11"
9
+ gem "activemodel", "3.2.11"
10
10
 
11
11
  gemspec :path=>"../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "appraisal", "~> 0.3.6"
6
+ gem "bson_ext", "~> 1.8"
7
+ gem "tzinfo"
8
+ gem "activesupport", :git=>"https://github.com/rails/rails.git"
9
+ gem "activemodel", :git=>"https://github.com/rails/rails.git"
10
+ gem "rails-observers", :git=>"https://github.com/rails/rails-observers.git"
11
+ gem "journey", :git=>"https://github.com/rails/journey.git"
12
+
13
+ gemspec :path=>"../"
@@ -0,0 +1,13 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "appraisal", "~> 0.3.6"
6
+ gem "bson_ext", "~> 1.8"
7
+ gem "tzinfo"
8
+ gem "activesupport", :git=>"https://github.com/rails/rails.git"
9
+ gem "activemodel", :git=>"https://github.com/rails/rails.git"
10
+ gem "protected_attributes", :git=>"https://github.com/rails/protected_attributes.git"
11
+ gem "journey", :git=>"https://github.com/rails/journey.git"
12
+
13
+ gemspec :path=>"../"
@@ -3,9 +3,10 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "appraisal", "~> 0.3.6"
6
- gem "bson_ext", "~> 1.5"
6
+ gem "bson_ext", "~> 1.8"
7
7
  gem "tzinfo"
8
8
  gem "activesupport", :git=>"https://github.com/rails/rails.git"
9
9
  gem "activemodel", :git=>"https://github.com/rails/rails.git"
10
+ gem "journey", :git=>"https://github.com/rails/journey.git"
10
11
 
11
12
  gemspec :path=>"../"
@@ -9,6 +9,18 @@ require 'mongomodel/log_subscriber'
9
9
 
10
10
  require 'active_support/core_ext/module/attribute_accessors'
11
11
 
12
+ begin
13
+ require "rails/observers/active_model/active_model"
14
+ rescue LoadError
15
+ # Either ActiveModel < 4 or rails-observers gem is not available
16
+ end
17
+
18
+ begin
19
+ require "protected_attributes"
20
+ rescue LoadError
21
+ # Either ActiveModel < 4 or protected_attributes gem is not available
22
+ end
23
+
12
24
  module MongoModel
13
25
  autoload :VERSION, 'mongomodel/version'
14
26
 
@@ -103,7 +115,7 @@ module MongoModel
103
115
  @_database ||= configuration.establish_connection
104
116
  end
105
117
 
106
- require 'mongomodel/railtie' if defined?(Rails)
118
+ require 'mongomodel/railtie' if defined?(Rails::Railtie)
107
119
 
108
120
  require 'mongomodel/compatibility/mongoid' if defined?(Mongoid)
109
121
  require 'mongomodel/compatibility/mongo_mapper' if defined?(MongoMapper)
@@ -3,25 +3,29 @@ module MongoModel
3
3
  module Protected
4
4
  extend ActiveSupport::Concern
5
5
 
6
- include ActiveModel::MassAssignmentSecurity
6
+ if defined?(ActiveModel::MassAssignmentSecurity)
7
+ include ActiveModel::MassAssignmentSecurity
7
8
 
8
- module ClassMethods
9
- def property(name, *args, &block)#:nodoc:
10
- property = super(name, *args, &block)
9
+ module ClassMethods
10
+ def property(name, *args, &block)#:nodoc:
11
+ property = super(name, *args, &block)
11
12
 
12
- attr_protected(name) if property.options[:protected]
13
- attr_accessible(name) if property.options[:accessible]
13
+ attr_protected(name) if property.options[:protected]
14
+ attr_accessible(name) if property.options[:accessible]
14
15
 
15
- property
16
+ property
17
+ end
16
18
  end
17
- end
18
19
 
19
- def assign_attributes(attrs, options={})
20
- if options[:without_protection]
21
- super
22
- else
23
- super(sanitize_for_mass_assignment(attrs, options[:as] || :default))
20
+ def assign_attributes(attrs, options={})
21
+ if options[:without_protection]
22
+ super
23
+ else
24
+ super(sanitize_for_mass_assignment(attrs, options[:as] || :default))
25
+ end
24
26
  end
27
+ elsif defined?(ActiveModel::DeprecatedMassAssignmentSecurity)
28
+ include ActiveModel::DeprecatedMassAssignmentSecurity
25
29
  end
26
30
  end
27
31
  end
@@ -1,35 +1,35 @@
1
- module MongoModel
2
- module Observing
3
- extend ActiveSupport::Concern
4
- include ActiveModel::Observing
5
- end
6
-
7
- class Observer < ActiveModel::Observer
8
- protected
9
- def observed_classes
10
- klasses = super
11
- klasses + klasses.map { |klass| klass.descendants }.flatten
12
- end
13
-
14
- def add_observer!(klass)
15
- super
16
- define_callbacks(klass)
17
- end
18
-
19
- def define_callbacks(klass)
20
- observer = self
21
- observer_name = observer.class.name.underscore.gsub('/', '__')
22
-
23
- MongoModel::Callbacks::CALLBACKS.each do |callback|
24
- next unless respond_to?(callback)
25
- callback_meth = :"_notify_#{observer_name}_for_#{callback}"
26
- unless klass.respond_to?(callback_meth)
27
- klass.send(:define_method, callback_meth) do |&block|
28
- observer.update(callback, self, &block)
29
- end
30
- klass.send(callback, callback_meth)
31
- end
32
- end
33
- end
34
- end
35
- end
1
+ module MongoModel
2
+ module Observing
3
+ extend ActiveSupport::Concern
4
+ include ActiveModel::Observing
5
+ end
6
+
7
+ class Observer < ActiveModel::Observer
8
+ protected
9
+ def observed_classes
10
+ klasses = super
11
+ klasses + klasses.map { |klass| klass.descendants }.flatten
12
+ end
13
+
14
+ def add_observer!(klass)
15
+ super
16
+ define_callbacks(klass)
17
+ end
18
+
19
+ def define_callbacks(klass)
20
+ observer = self
21
+ observer_name = observer.class.name.underscore.gsub('/', '__')
22
+
23
+ MongoModel::Callbacks::CALLBACKS.each do |callback|
24
+ next unless respond_to?(callback)
25
+ callback_meth = :"_notify_#{observer_name}_for_#{callback}"
26
+ unless klass.respond_to?(callback_meth)
27
+ klass.send(:define_method, callback_meth) do |&block|
28
+ observer.update(callback, self, &block)
29
+ end
30
+ klass.send(callback, callback_meth)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -153,7 +153,7 @@ module MongoModel
153
153
  end
154
154
 
155
155
  def save_to_collection
156
- collection.save(to_mongo, :safe => self.class.save_safely?)
156
+ collection.save(to_mongo, :w => self.class.save_safely? ? 1 : 0)
157
157
  set_new_record(false)
158
158
  true
159
159
  rescue Mongo::OperationFailure => e
@@ -10,7 +10,7 @@ module MongoModel
10
10
  include Translation
11
11
  include Validations
12
12
  include Callbacks
13
- include Observing
13
+ include Observing if defined?(ActiveModel::Observing)
14
14
 
15
15
  include Associations
16
16
 
@@ -32,7 +32,7 @@ module MongoModel
32
32
  # Define our own to_time method as DateTime.to_time in ActiveSupport may return
33
33
  # the DateTime object unchanged, whereas BSON expects an actual Time object.
34
34
  def to_time(dt)
35
- ::Time.utc_time(dt.year, dt.month, dt.day, dt.hour, dt.min, dt.sec)
35
+ ::Time.utc(dt.year, dt.month, dt.day, dt.hour, dt.min, dt.sec)
36
36
  end
37
37
  end
38
38
  end
@@ -1,3 +1,3 @@
1
1
  module MongoModel
2
- VERSION = "0.4.8"
2
+ VERSION = "0.4.9"
3
3
  end
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
 
17
17
  s.add_dependency "activesupport", ">= 3.1"
18
18
  s.add_dependency "activemodel", ">= 3.1"
19
- s.add_dependency "mongo", "~> 1.5"
19
+ s.add_dependency "mongo", "~> 1.8"
20
20
 
21
21
  s.add_development_dependency "bundler", ">= 1.0.0"
22
22
  s.add_development_dependency "rspec", "~> 2.8"
@@ -1,84 +1,86 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module MongoModel
4
- specs_for(Document, EmbeddedDocument) do
5
- define_class(:TestDocument, described_class) do
6
- property :foo, String
7
- property :bar, String
8
- end
4
+ if ActiveModel::VERSION::STRING < '4.0' || Gem.loaded_specs['protected_attributes']
5
+ specs_for(Document, EmbeddedDocument) do
6
+ define_class(:TestDocument, described_class) do
7
+ property :foo, String
8
+ property :bar, String
9
+ end
9
10
 
10
- subject { TestDocument.new }
11
+ subject { TestDocument.new }
11
12
 
12
- describe "#attr_protected" do
13
- before(:each) do
14
- TestDocument.attr_protected :foo
15
- end
13
+ describe "#attr_protected" do
14
+ before(:each) do
15
+ TestDocument.attr_protected :foo
16
+ end
16
17
 
17
- it "disallows the attribute to be mass-assigned via attributes=" do
18
- subject.attributes = { :foo => 'value of foo' }
19
- subject.foo.should be_nil
20
- end
18
+ it "disallows the attribute to be mass-assigned via attributes=" do
19
+ subject.attributes = { :foo => 'value of foo' }
20
+ subject.foo.should be_nil
21
+ end
21
22
 
22
- it "does not disallow the attribute to be assigned individually" do
23
- subject.foo = 'value of foo'
24
- subject.foo.should == 'value of foo'
25
- end
23
+ it "does not disallow the attribute to be assigned individually" do
24
+ subject.foo = 'value of foo'
25
+ subject.foo.should == 'value of foo'
26
+ end
26
27
 
27
- it "does not disallow other attributes to be mass-assigned via attributes=" do
28
- subject.attributes = { :bar => 'value of bar' }
29
- subject.bar.should == 'value of bar'
30
- end
28
+ it "does not disallow other attributes to be mass-assigned via attributes=" do
29
+ subject.attributes = { :bar => 'value of bar' }
30
+ subject.bar.should == 'value of bar'
31
+ end
31
32
 
32
- it "accepts multiple attributes" do
33
- TestDocument.attr_protected :foo, :bar
33
+ it "accepts multiple attributes" do
34
+ TestDocument.attr_protected :foo, :bar
34
35
 
35
- subject.attributes = { :foo => 'value of foo', :bar => 'value of bar' }
36
- subject.foo.should be_nil
37
- subject.bar.should be_nil
36
+ subject.attributes = { :foo => 'value of foo', :bar => 'value of bar' }
37
+ subject.foo.should be_nil
38
+ subject.bar.should be_nil
39
+ end
38
40
  end
39
- end
40
41
 
41
- describe "#attr_accessible" do
42
- before(:each) do
43
- TestDocument.attr_accessible :foo
44
- end
42
+ describe "#attr_accessible" do
43
+ before(:each) do
44
+ TestDocument.attr_accessible :foo
45
+ end
45
46
 
46
- it "allows the attribute to be mass-assigned via attributes=" do
47
- subject.attributes = { :foo => 'value of foo' }
48
- subject.foo.should == 'value of foo'
49
- end
47
+ it "allows the attribute to be mass-assigned via attributes=" do
48
+ subject.attributes = { :foo => 'value of foo' }
49
+ subject.foo.should == 'value of foo'
50
+ end
50
51
 
51
- it "does not disallow other attributes to be mass-assigned via attributes=" do
52
- subject.attributes = { :bar => 'value of bar' }
53
- subject.bar.should be_nil
54
- end
52
+ it "does not disallow other attributes to be mass-assigned via attributes=" do
53
+ subject.attributes = { :bar => 'value of bar' }
54
+ subject.bar.should be_nil
55
+ end
55
56
 
56
- it "does not disallow others attributes to be assigned individually" do
57
- subject.bar = 'value of bar'
58
- subject.bar.should == 'value of bar'
59
- end
57
+ it "does not disallow others attributes to be assigned individually" do
58
+ subject.bar = 'value of bar'
59
+ subject.bar.should == 'value of bar'
60
+ end
60
61
 
61
- it "accepts multiple attributes" do
62
- TestDocument.attr_accessible :foo, :bar
62
+ it "accepts multiple attributes" do
63
+ TestDocument.attr_accessible :foo, :bar
63
64
 
64
- subject.attributes = { :foo => 'value of foo', :bar => 'value of bar' }
65
- subject.foo.should == 'value of foo'
66
- subject.bar.should == 'value of bar'
65
+ subject.attributes = { :foo => 'value of foo', :bar => 'value of bar' }
66
+ subject.foo.should == 'value of foo'
67
+ subject.bar.should == 'value of bar'
68
+ end
67
69
  end
68
- end
69
70
 
70
- describe "#property" do
71
- context "with :protected option" do
72
- it "makes the attribute protected" do
73
- TestDocument.should_receive(:attr_protected).with(:baz)
74
- TestDocument.property :baz, String, :protected => true
71
+ describe "#property" do
72
+ context "with :protected option" do
73
+ it "makes the attribute protected" do
74
+ TestDocument.should_receive(:attr_protected).with(:baz)
75
+ TestDocument.property :baz, String, :protected => true
76
+ end
75
77
  end
76
- end
77
78
 
78
- context "with :accessible option" do
79
- it "makes the attribute accessible" do
80
- TestDocument.should_receive(:attr_accessible).with(:baz)
81
- TestDocument.property :baz, String, :accessible => true
79
+ context "with :accessible option" do
80
+ it "makes the attribute accessible" do
81
+ TestDocument.should_receive(:attr_accessible).with(:baz)
82
+ TestDocument.property :baz, String, :accessible => true
83
+ end
82
84
  end
83
85
  end
84
86
  end
@@ -1,32 +1,34 @@
1
- require 'spec_helper'
2
-
3
- module MongoModel
4
- specs_for(Document) do
5
- describe "observing" do
6
- define_class(:TestDocument, described_class)
7
- define_class(:TestObserver, Observer) do
8
- observe :test_document
9
-
10
- attr_accessor :callback
11
-
12
- def after_save(model)
13
- @callback.call(model) unless @callback.nil?
14
- end
15
- end
16
-
17
- subject { TestDocument.new }
18
-
19
- it "has an #instance method to access the observer singleton" do
20
- TestObserver.instance.should eq(TestObserver.instance)
21
- end
22
-
23
- it "invokes the TestObserver singleton's after_save method after saving" do
24
- callback = stub
25
- callback.should_receive(:call).with(subject)
26
-
27
- TestObserver.instance.callback = callback
28
- subject.save
29
- end
30
- end
31
- end
1
+ require 'spec_helper'
2
+
3
+ module MongoModel
4
+ if ActiveModel::VERSION::STRING < '4.0' || Gem.loaded_specs['rails-observers']
5
+ specs_for(Document) do
6
+ describe "observing" do
7
+ define_class(:TestDocument, described_class)
8
+ define_class(:TestObserver, Observer) do
9
+ observe :test_document
10
+
11
+ attr_accessor :callback
12
+
13
+ def after_save(model)
14
+ @callback.call(model) unless @callback.nil?
15
+ end
16
+ end
17
+
18
+ subject { TestDocument.new }
19
+
20
+ it "has an #instance method to access the observer singleton" do
21
+ TestObserver.instance.should eq(TestObserver.instance)
22
+ end
23
+
24
+ it "invokes the TestObserver singleton's after_save method after saving" do
25
+ callback = stub
26
+ callback.should_receive(:call).with(subject)
27
+
28
+ TestObserver.instance.callback = callback
29
+ subject.save
30
+ end
31
+ end
32
+ end
33
+ end
32
34
  end
@@ -1,6 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
- Bundler.require
3
+ Bundler.setup
4
4
 
5
5
  require 'rspec'
6
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongomodel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.4.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-22 00:00:00.000000000 Z
12
+ date: 2013-01-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -50,7 +50,7 @@ dependencies:
50
50
  requirements:
51
51
  - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: '1.5'
53
+ version: '1.8'
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '1.5'
61
+ version: '1.8'
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: bundler
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -127,6 +127,8 @@ files:
127
127
  - gemfiles/mongoid.gemfile
128
128
  - gemfiles/rails-3.1.gemfile
129
129
  - gemfiles/rails-3.2.gemfile
130
+ - gemfiles/rails-4-observers.gemfile
131
+ - gemfiles/rails-4-protected-attributes.gemfile
130
132
  - gemfiles/rails-4.gemfile
131
133
  - lib/mongomodel.rb
132
134
  - lib/mongomodel/attributes/mongo.rb
@@ -298,7 +300,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
298
300
  version: '0'
299
301
  segments:
300
302
  - 0
301
- hash: -1652112125246390451
303
+ hash: -157518307966196905
302
304
  required_rubygems_version: !ruby/object:Gem::Requirement
303
305
  none: false
304
306
  requirements: