active_attr 0.3.0 → 0.4.0

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/.gitignore CHANGED
@@ -4,4 +4,5 @@
4
4
  coverage
5
5
  doc
6
6
  Gemfile.lock
7
+ gemfiles/*.gemfile.lock
7
8
  pkg/*
data/.travis.yml CHANGED
@@ -3,3 +3,6 @@ rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
5
  bundler_args: --without development
6
+ gemfile:
7
+ - Gemfile
8
+ - gemfiles/rails_head.gemfile
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # ActiveAttr 0.4.0 (November 26, 2011) #
2
+
3
+ * Added Model
4
+ * Support for ActiveModel 3.2
5
+
1
6
  # ActiveAttr 0.3.0 (November 26, 2011) #
2
7
 
3
8
  * Added BlockInitialization
@@ -7,7 +12,7 @@
7
12
  * Added QueryAttributes
8
13
  * Added UnknownAttributeError
9
14
  * Attributes now honors getters/setters when calling #read_attribute,
10
- #write_attribute, #[], and #[]=
15
+ \#write_attribute, #[], and #[]=
11
16
  * Attributes now raises DangerousAttributeError when defining an attribute
12
17
  whose methods would conflict with an existing method
13
18
  * Attributes now raises UnknownAttributeError when getting/setting any
data/README.md CHANGED
@@ -12,6 +12,16 @@ the wheel.
12
12
 
13
13
  ## Modules ##
14
14
 
15
+ ### Model ###
16
+
17
+ The Model module is a shortcut for incorporating the most common model
18
+ functionality into your model with one include. All of the following modules
19
+ are included when you include Model.
20
+
21
+ class Person
22
+ include ActiveAttr::Model
23
+ end
24
+
15
25
  ### Attributes ###
16
26
 
17
27
  Including the Attributes module into your class gives you a DSL for defining
@@ -133,10 +143,20 @@ providing instance methods for querying your attributes
133
143
  person.first_name? #=> true
134
144
  person.last_name? #=> false
135
145
 
136
- ## RSpec Integration ##
146
+ ## Integrations ##
147
+
148
+ ### Ruby on Rails ###
149
+
150
+ When using ActiveAttr inside a Rails application, ActiveAttr will configure
151
+ your models' default logger to use the Rails logger automatically. Just
152
+ include ActiveAttr in your Gemfile.
153
+
154
+ gem "active_attr"
155
+
156
+ ### RSpec ###
137
157
 
138
158
  ActiveAttr comes with matchers and RSpec integration to assist you in testing
139
- your models.
159
+ your models. The matchers also work with compatible frameworks like Shoulda.
140
160
 
141
161
  require "active_attr/rspec"
142
162
 
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec :development_group => :test, :path => ".."
4
+
5
+ git "git://github.com/rails/rails.git" do
6
+ gem "activemodel"
7
+ gem "activesupport"
8
+ end
data/lib/active_attr.rb CHANGED
@@ -17,6 +17,7 @@ module ActiveAttr
17
17
  autoload :Logger
18
18
  autoload :MassAssignment
19
19
  autoload :MassAssignmentSecurity
20
+ autoload :Model
20
21
  autoload :QueryAttributes
21
22
  autoload :StrictMassAssignment
22
23
  autoload :UnknownAttributeError
@@ -29,7 +29,7 @@ module ActiveAttr
29
29
  DEPRECATED_OBJECT_METHODS = %w(id type)
30
30
 
31
31
  included do
32
- attribute_method_suffix ""
32
+ attribute_method_suffix "" if attribute_method_matchers.none? { |matcher| matcher.prefix == "" && matcher.suffix == "" }
33
33
  attribute_method_suffix "="
34
34
  end
35
35
 
@@ -0,0 +1,28 @@
1
+ require "active_attr/basic_model"
2
+ require "active_attr/block_initialization"
3
+ require "active_attr/logger"
4
+ require "active_attr/mass_assignment_security"
5
+ require "active_attr/query_attributes"
6
+ require "active_support/concern"
7
+
8
+ module ActiveAttr
9
+ # Model is a shortcut for incorporating the most common model
10
+ # functionality into your model with one include
11
+ #
12
+ # See the included modules to learn more.
13
+ #
14
+ # @example Usage
15
+ # class Person
16
+ # include ActiveAttr::Model
17
+ # end
18
+ #
19
+ # @since 0.4.0
20
+ module Model
21
+ extend ActiveSupport::Concern
22
+ include BasicModel
23
+ include BlockInitialization
24
+ include Logger
25
+ include MassAssignmentSecurity
26
+ include QueryAttributes
27
+ end
28
+ end
@@ -1,5 +1,5 @@
1
1
  module ActiveAttr
2
2
  # Complete version string
3
3
  # @since 0.1.0
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
@@ -65,8 +65,14 @@ module ActiveAttr
65
65
  let :model_class do
66
66
  Class.new do
67
67
  include Attributes
68
- include ActiveModel::Serializers::JSON
69
- include ActiveModel::Serializers::Xml
68
+
69
+ if defined? ActiveModel::Serializable
70
+ include ActiveModel::Serializable::JSON
71
+ include ActiveModel::Serializable::XML
72
+ else
73
+ include ActiveModel::Serializers::JSON
74
+ include ActiveModel::Serializers::Xml
75
+ end
70
76
 
71
77
  attribute :first_name
72
78
  attribute :last_name
@@ -0,0 +1,71 @@
1
+ require "spec_helper"
2
+ require "active_attr/model"
3
+
4
+ module ActiveAttr
5
+ describe Model do
6
+ let :model_class do
7
+ Class.new do
8
+ include Model
9
+
10
+ attribute :first_name
11
+ attribute :last_name
12
+
13
+ attr_protected :last_name
14
+
15
+ def self.name
16
+ "Person"
17
+ end
18
+ end
19
+ end
20
+
21
+ subject { model_class.new }
22
+ it_should_behave_like "ActiveModel"
23
+
24
+ it "reads and writes attributes" do
25
+ subject.first_name = "Chris"
26
+ subject.first_name.should == "Chris"
27
+ subject.attributes["first_name"].should == "Chris"
28
+ end
29
+
30
+ it "can query attributes" do
31
+ subject.first_name?.should be_false
32
+ subject.first_name = "Chris"
33
+ subject.first_name?.should be_true
34
+ end
35
+
36
+ it "initializes with a block that can use attributes" do
37
+ model_class.new do |person|
38
+ person.write_attribute :first_name, "Chris"
39
+ end.read_attribute(:first_name).should == "Chris"
40
+ end
41
+
42
+ it "processes mass assignment yielding an initialization block" do
43
+ model_class.new(:first_name => "Chris") do |person|
44
+ person.first_name.should == "Chris"
45
+ end
46
+ end
47
+
48
+ it "has a logger" do
49
+ logger = double("logger")
50
+ model_class.logger?.should be_false
51
+ subject.logger?.should be_false
52
+
53
+ model_class.logger = logger
54
+
55
+ model_class.logger?.should be_true
56
+ model_class.logger.should == logger
57
+ subject.logger?.should be_true
58
+ subject.logger.should == logger
59
+ end
60
+
61
+ it "supports mass assignment with security" do
62
+ person = model_class.new(:first_name => "Chris", :last_name => "Griego")
63
+ person.first_name.should == "Chris"
64
+ person.last_name.should be_nil
65
+ end
66
+
67
+ it "does not use strict mass assignment" do
68
+ expect { subject.assign_attributes :middle_initial => "J" }.not_to raise_error
69
+ end
70
+ end
71
+ end
@@ -8,7 +8,7 @@ module ActiveAttr
8
8
  include BasicModel
9
9
 
10
10
  def self.name
11
- "Foo"
11
+ "Person"
12
12
  end
13
13
  end
14
14
  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.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-11-26 00:00:00.000000000Z
13
+ date: 2011-11-27 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
17
- requirement: &70119267606720 !ruby/object:Gem::Requirement
17
+ requirement: &70208496667400 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '3.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70119267606720
25
+ version_requirements: *70208496667400
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activesupport
28
- requirement: &70119267605900 !ruby/object:Gem::Requirement
28
+ requirement: &70208496659840 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '3.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70119267605900
36
+ version_requirements: *70208496659840
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: bundler
39
- requirement: &70119267605220 !ruby/object:Gem::Requirement
39
+ requirement: &70208496720580 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '1.0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70119267605220
47
+ version_requirements: *70208496720580
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: factory_girl
50
- requirement: &70119267604420 !ruby/object:Gem::Requirement
50
+ requirement: &70208496732300 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '2.2'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70119267604420
58
+ version_requirements: *70208496732300
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: rake
61
- requirement: &70119267603600 !ruby/object:Gem::Requirement
61
+ requirement: &70208496743100 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: 0.9.0
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70119267603600
69
+ version_requirements: *70208496743100
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rspec
72
- requirement: &70119267602780 !ruby/object:Gem::Requirement
72
+ requirement: &70208496750220 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ~>
@@ -77,7 +77,7 @@ dependencies:
77
77
  version: '2.6'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *70119267602780
80
+ version_requirements: *70208496750220
81
81
  description: Create plain old ruby models without reinventing the wheel.
82
82
  email:
83
83
  - cgriego@gmail.com
@@ -98,6 +98,7 @@ files:
98
98
  - README.md
99
99
  - Rakefile
100
100
  - active_attr.gemspec
101
+ - gemfiles/rails_head.gemfile
101
102
  - lib/active_attr.rb
102
103
  - lib/active_attr/attribute_definition.rb
103
104
  - lib/active_attr/attributes.rb
@@ -111,6 +112,7 @@ files:
111
112
  - lib/active_attr/mass_assignment_security.rb
112
113
  - lib/active_attr/matchers.rb
113
114
  - lib/active_attr/matchers/have_attribute_matcher.rb
115
+ - lib/active_attr/model.rb
114
116
  - lib/active_attr/query_attributes.rb
115
117
  - lib/active_attr/railtie.rb
116
118
  - lib/active_attr/rspec.rb
@@ -120,6 +122,7 @@ files:
120
122
  - lib/active_attr/version.rb
121
123
  - spec/functional/active_attr/attributes_spec.rb
122
124
  - spec/functional/active_attr/chainable_initialization_spec.rb
125
+ - spec/functional/active_attr/model_spec.rb
123
126
  - spec/functional/active_attr/query_attributes_spec.rb
124
127
  - spec/spec_helper.rb
125
128
  - spec/support/active_model_lint.rb
@@ -154,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
154
157
  version: '0'
155
158
  segments:
156
159
  - 0
157
- hash: -4548017716057297773
160
+ hash: 2277450769391114254
158
161
  required_rubygems_version: !ruby/object:Gem::Requirement
159
162
  none: false
160
163
  requirements:
@@ -163,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
166
  version: '0'
164
167
  segments:
165
168
  - 0
166
- hash: -4548017716057297773
169
+ hash: 2277450769391114254
167
170
  requirements: []
168
171
  rubyforge_project: active_attr
169
172
  rubygems_version: 1.8.10
@@ -173,6 +176,7 @@ summary: What ActiveModel left out
173
176
  test_files:
174
177
  - spec/functional/active_attr/attributes_spec.rb
175
178
  - spec/functional/active_attr/chainable_initialization_spec.rb
179
+ - spec/functional/active_attr/model_spec.rb
176
180
  - spec/functional/active_attr/query_attributes_spec.rb
177
181
  - spec/spec_helper.rb
178
182
  - spec/support/active_model_lint.rb