active_attr 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of active_attr might be problematic. Click here for more details.

data/.travis.yml CHANGED
@@ -6,6 +6,7 @@ rvm:
6
6
  bundler_args: --without development
7
7
  gemfile:
8
8
  - Gemfile
9
+ - gemfiles/rails_3_0.gemfile
9
10
  - gemfiles/rails_3_1.gemfile
10
11
  - gemfiles/rails_head.gemfile
11
12
  matrix:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # ActiveAttr 0.5.1 (March 16, 2012) #
2
+
3
+ * ActiveAttr now supports Rails 3.0.2+ (Egor Baranov)
4
+
1
5
  # ActiveAttr 0.5.0 (March 11, 2012) #
2
6
 
3
7
  * ActiveAttr is now Ruby warning free
data/active_attr.gemspec CHANGED
@@ -18,8 +18,8 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- s.add_runtime_dependency "activemodel", ">= 3.1", "< 4.1"
22
- s.add_runtime_dependency "activesupport", ">= 3.1", "< 4.1"
21
+ s.add_runtime_dependency "activemodel", ">= 3.0.2", "< 4.1"
22
+ s.add_runtime_dependency "activesupport", ">= 3.0.2", "< 4.1"
23
23
 
24
24
  s.add_development_dependency "bundler", "~> 1.0"
25
25
  s.add_development_dependency "factory_girl", "~> 2.2"
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec :development_group => :test, :path => ".."
4
+
5
+ gem "activemodel", "~> 3.0.2"
6
+ gem "activesupport", "~> 3.0.2"
@@ -1,6 +1,3 @@
1
- require 'active_support/core_ext/hash/reverse_merge'
2
- require 'active_support/core_ext/string/inflections'
3
-
4
1
  module ActiveAttr
5
2
  # Represents an attribute for reflection
6
3
  #
@@ -165,7 +165,9 @@ module ActiveAttr
165
165
  def attribute(name, options={})
166
166
  AttributeDefinition.new(name, options).tap do |attribute_definition|
167
167
  attribute_name = attribute_definition.name.to_s
168
- define_attribute_method attribute_definition.name unless attribute_names.include? attribute_name
168
+ # Force active model to generate attribute methods
169
+ remove_instance_variable("@attribute_methods_generated") if instance_variable_defined?("@attribute_methods_generated")
170
+ define_attribute_methods([attribute_definition.name]) unless attribute_names.include? attribute_name
169
171
  attributes[attribute_name] = attribute_definition
170
172
  end
171
173
  end
@@ -32,8 +32,13 @@ module ActiveAttr
32
32
  # @since 0.3.0
33
33
  def assign_attributes(new_attributes, options={})
34
34
  if new_attributes && !options[:without_protection]
35
- mass_assignment_role = options[:as] || :default
36
- new_attributes = sanitize_for_mass_assignment new_attributes, mass_assignment_role
35
+ if method(:sanitize_for_mass_assignment).arity.abs > 1
36
+ mass_assignment_role = options[:as] || :default
37
+ new_attributes = sanitize_for_mass_assignment new_attributes, mass_assignment_role
38
+ else
39
+ # Rails 3.0 has no roles support in mass assignment
40
+ new_attributes = sanitize_for_mass_assignment new_attributes
41
+ end
37
42
  end
38
43
 
39
44
  super
@@ -25,7 +25,9 @@ module ActiveAttr
25
25
  #
26
26
  # @since 0.5.0
27
27
  def call(value)
28
- if value.respond_to? :to_d
28
+ if value.is_a? BigDecimal
29
+ value
30
+ elsif value.respond_to? :to_d
29
31
  value.to_d
30
32
  else
31
33
  BigDecimal.new value.to_s
@@ -1,5 +1,5 @@
1
1
  module ActiveAttr
2
2
  # Complete version string
3
3
  # @since 0.1.0
4
- VERSION = "0.5.0"
4
+ VERSION = "0.5.1"
5
5
  end
@@ -9,8 +9,10 @@ module ActiveAttr
9
9
  subject { model_class.new }
10
10
 
11
11
  let :model_class do
12
- Class.new do
13
- include ActiveAttr::AttributeDefaults
12
+ Class.new.tap do |model_class|
13
+ model_class.class_eval do
14
+ include ActiveAttr::AttributeDefaults
15
+ end
14
16
  end
15
17
  end
16
18
 
@@ -5,6 +5,31 @@ require "factory_girl"
5
5
 
6
6
  module ActiveAttr
7
7
  describe Attributes do
8
+ context "defining multiple attributes" do
9
+ let :model_class do
10
+ Class.new do
11
+ include Attributes
12
+
13
+ attribute :name
14
+ attribute :id
15
+
16
+ def id
17
+ if defined?(super)
18
+ super
19
+ else
20
+ object_id
21
+ end
22
+ end unless instance_methods(false).include?("id")
23
+ end
24
+ end
25
+
26
+ subject { model_class.new }
27
+
28
+ it "correctly defines methods for the attributes instead of relying on method_missing" do
29
+ subject.id.should be_nil
30
+ end
31
+ end
32
+
8
33
  context "subclassing a model" do
9
34
  let :parent_class do
10
35
  Class.new do
@@ -17,7 +42,7 @@ module ActiveAttr
17
42
 
18
43
  let! :child_class do
19
44
  Class.new(parent_class).tap do |child_class|
20
- child_class.instance_eval do
45
+ child_class.class_eval do
21
46
  attribute :child
22
47
  attribute :redefined, :type => String
23
48
  end
@@ -171,7 +196,7 @@ module ActiveAttr
171
196
  end
172
197
 
173
198
  it "defining an attribute that conflicts with ActiveModel::AttributeMethods raises DangerousAttributeError" do
174
- expect { model_class.attribute(:attribute_method_matchers) }.to raise_error DangerousAttributeError, %{an attribute method named "attribute_method_matchers" would conflict with an existing method}
199
+ expect { model_class.attribute(:inspect) }.to raise_error DangerousAttributeError, %{an attribute method named "inspect" would conflict with an existing method}
175
200
  end
176
201
 
177
202
  it "defining an :id attribute does not raise" do
@@ -204,19 +229,21 @@ module ActiveAttr
204
229
  end
205
230
 
206
231
  let :dangerous_model_class do
207
- Class.new do
208
- include Attributes
232
+ Class.new.tap do |dangerous_model_class|
233
+ dangerous_model_class.class_eval do
234
+ include Attributes
209
235
 
210
- def method_missing(method_name, *)
211
- super if %w(my_proper_missing_method my_less_proper_missing_method).include? method_name.to_s
212
- end
236
+ def method_missing(method_name, *)
237
+ super if %w(my_proper_missing_method my_less_proper_missing_method).include? method_name.to_s
238
+ end
213
239
 
214
- def respond_to_missing?(method_name, *)
215
- method_name.to_s == "my_proper_missing_method" || super
216
- end
240
+ def respond_to_missing?(method_name, *)
241
+ method_name.to_s == "my_proper_missing_method" || super
242
+ end
217
243
 
218
- def respond_to?(method_name, include_private=false)
219
- super || method_name.to_s == "my_less_proper_missing_method" || (RUBY_VERSION < "1.9" && respond_to_missing?(method_name, include_private))
244
+ def respond_to?(method_name, include_private=false)
245
+ super || method_name.to_s == "my_less_proper_missing_method" || (RUBY_VERSION < "1.9" && respond_to_missing?(method_name, include_private))
246
+ end
220
247
  end
221
248
  end
222
249
  end
@@ -4,6 +4,14 @@ require "active_attr/query_attributes"
4
4
  module ActiveAttr
5
5
  describe QueryAttributes do
6
6
  context "defining dangerous attributes" do
7
+ let :parent_class do
8
+ Class.new.tap do |parent_class|
9
+ parent_class.class_eval do
10
+ include QueryAttributes
11
+ end
12
+ end
13
+ end
14
+
7
15
  shared_examples "defining a dangerous queryable attribute" do
8
16
  it "defining an attribute that conflicts with ActiveModel::AttributeMethods raises DangerousAttributeError" do
9
17
  expect { model_class.attribute(:attribute_method) }.to raise_error DangerousAttributeError, %{an attribute method named "attribute_method?" would conflict with an existing method}
@@ -19,12 +27,12 @@ module ActiveAttr
19
27
  end
20
28
 
21
29
  context "on a model class" do
22
- let(:model_class) { Class.new { include QueryAttributes } }
30
+ let(:model_class) { parent_class }
23
31
  include_examples "defining a dangerous queryable attribute"
24
32
  end
25
33
 
26
34
  context "on a child class" do
27
- let(:model_class) { Class.new(Class.new { include QueryAttributes }) }
35
+ let(:model_class) { Class.new(parent_class) }
28
36
  include_examples "defining a dangerous queryable attribute"
29
37
  end
30
38
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "bundler/setup"
2
2
  require "rspec/autorun"
3
+ require "active_model/version"
3
4
 
4
5
  # Requires supporting files with custom matchers and macros, etc,
5
6
  # in ./support/ and its subdirectories.
@@ -8,4 +9,8 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |file| require file }
8
9
  RSpec.configure do |config|
9
10
  config.mock_framework = :rspec
10
11
  config.treat_symbols_as_metadata_keys_with_true_values = true # default in RSpec 3
12
+
13
+ config.filter_run_excluding :active_model_version => lambda { |requirement|
14
+ !Gem::Requirement.create(requirement).satisfied_by?(Gem::Version.new(ActiveModel::VERSION::STRING))
15
+ }
11
16
  end
@@ -26,11 +26,11 @@ module ActiveAttr
26
26
 
27
27
  it "includes declared nil attribute defaults" do
28
28
  subject.should include "age"
29
- subject['age'].should be_nil
29
+ subject["age"].should be_nil
30
30
  end
31
31
 
32
32
  it "includes declared dynamic attribute defaults" do
33
- subject['created_at'].should be_a_kind_of Time
33
+ subject["created_at"].should be_a_kind_of Time
34
34
  end
35
35
  end
36
36
 
@@ -15,14 +15,19 @@ module ActiveAttr
15
15
  shared_examples "secure mass assignment method", :secure_mass_assignment_method => true do
16
16
  include_examples "mass assignment method"
17
17
 
18
- it "ignores assigning a protected attribute" do
18
+ it "ignores assigning an attribute protected by role-based security", :active_model_version => ">= 3.1.0" do
19
19
  person = mass_assign_attributes(:age => 21)
20
20
  person.age.should be_nil
21
21
  end
22
+
23
+ it "ignores assigning a protected attribute" do
24
+ person = mass_assign_attributes(:first_name => "Chris")
25
+ person.age.should be_nil
26
+ end
22
27
  end
23
28
 
24
29
  shared_examples "secure mass assignment method with options", :secure_mass_assignment_method_with_options => true do
25
- it "supports role-based mass assignment security" do
30
+ it "supports role-based mass assignment security", :active_model_version => ">= 3.1.0" do
26
31
  person = mass_assign_attributes_with_options({ :age => 21 }, :as => :admin)
27
32
  person.age.should == 21
28
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_attr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,39 +10,39 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-03-12 00:00:00.000000000Z
13
+ date: 2012-03-16 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
17
- requirement: &70109482810160 !ruby/object:Gem::Requirement
17
+ requirement: &70128915108520 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
21
21
  - !ruby/object:Gem::Version
22
- version: '3.1'
22
+ version: 3.0.2
23
23
  - - <
24
24
  - !ruby/object:Gem::Version
25
25
  version: '4.1'
26
26
  type: :runtime
27
27
  prerelease: false
28
- version_requirements: *70109482810160
28
+ version_requirements: *70128915108520
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: activesupport
31
- requirement: &70109482808160 !ruby/object:Gem::Requirement
31
+ requirement: &70128915106640 !ruby/object:Gem::Requirement
32
32
  none: false
33
33
  requirements:
34
34
  - - ! '>='
35
35
  - !ruby/object:Gem::Version
36
- version: '3.1'
36
+ version: 3.0.2
37
37
  - - <
38
38
  - !ruby/object:Gem::Version
39
39
  version: '4.1'
40
40
  type: :runtime
41
41
  prerelease: false
42
- version_requirements: *70109482808160
42
+ version_requirements: *70128915106640
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: bundler
45
- requirement: &70109482806600 !ruby/object:Gem::Requirement
45
+ requirement: &70128915104720 !ruby/object:Gem::Requirement
46
46
  none: false
47
47
  requirements:
48
48
  - - ~>
@@ -50,10 +50,10 @@ dependencies:
50
50
  version: '1.0'
51
51
  type: :development
52
52
  prerelease: false
53
- version_requirements: *70109482806600
53
+ version_requirements: *70128915104720
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: factory_girl
56
- requirement: &70109482805800 !ruby/object:Gem::Requirement
56
+ requirement: &70128915103800 !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
59
  - - ~>
@@ -61,10 +61,10 @@ dependencies:
61
61
  version: '2.2'
62
62
  type: :development
63
63
  prerelease: false
64
- version_requirements: *70109482805800
64
+ version_requirements: *70128915103800
65
65
  - !ruby/object:Gem::Dependency
66
66
  name: rake
67
- requirement: &70109482804840 !ruby/object:Gem::Requirement
67
+ requirement: &70128915102820 !ruby/object:Gem::Requirement
68
68
  none: false
69
69
  requirements:
70
70
  - - ~>
@@ -72,10 +72,10 @@ dependencies:
72
72
  version: 0.9.0
73
73
  type: :development
74
74
  prerelease: false
75
- version_requirements: *70109482804840
75
+ version_requirements: *70128915102820
76
76
  - !ruby/object:Gem::Dependency
77
77
  name: rspec
78
- requirement: &70109482803980 !ruby/object:Gem::Requirement
78
+ requirement: &70128915102080 !ruby/object:Gem::Requirement
79
79
  none: false
80
80
  requirements:
81
81
  - - ~>
@@ -83,10 +83,10 @@ dependencies:
83
83
  version: '2.6'
84
84
  type: :development
85
85
  prerelease: false
86
- version_requirements: *70109482803980
86
+ version_requirements: *70128915102080
87
87
  - !ruby/object:Gem::Dependency
88
88
  name: tzinfo
89
- requirement: &70109482803280 !ruby/object:Gem::Requirement
89
+ requirement: &70128915101040 !ruby/object:Gem::Requirement
90
90
  none: false
91
91
  requirements:
92
92
  - - ~>
@@ -94,7 +94,7 @@ dependencies:
94
94
  version: 0.3.29
95
95
  type: :development
96
96
  prerelease: false
97
- version_requirements: *70109482803280
97
+ version_requirements: *70128915101040
98
98
  description: Create plain old ruby models without reinventing the wheel.
99
99
  email:
100
100
  - cgriego@gmail.com
@@ -115,6 +115,7 @@ files:
115
115
  - README.md
116
116
  - Rakefile
117
117
  - active_attr.gemspec
118
+ - gemfiles/rails_3_0.gemfile
118
119
  - gemfiles/rails_3_1.gemfile
119
120
  - gemfiles/rails_head.gemfile
120
121
  - lib/active_attr.rb
@@ -199,7 +200,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
199
200
  version: '0'
200
201
  segments:
201
202
  - 0
202
- hash: -2941939635939237766
203
+ hash: 4554673670402993662
203
204
  required_rubygems_version: !ruby/object:Gem::Requirement
204
205
  none: false
205
206
  requirements:
@@ -208,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
209
  version: '0'
209
210
  segments:
210
211
  - 0
211
- hash: -2941939635939237766
212
+ hash: 4554673670402993662
212
213
  requirements: []
213
214
  rubyforge_project: active_attr
214
215
  rubygems_version: 1.8.10