ar_default_values 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb2ebcc362d9a7af3e6fe45f4f0abba93245d43a
4
- data.tar.gz: db72b094fa7f00e1d0ce1b4880bdc570b78f0dd1
3
+ metadata.gz: 5e377838e48ccad8237c57909a67c15cc5e43223
4
+ data.tar.gz: 8ac4024d5e11a96f357f4ba25c20f4b071338bbf
5
5
  SHA512:
6
- metadata.gz: 6529ca967259cf03e8f439c2dec27912ca1b18f3e771e333ce382301e30b1e9ebd199ca346ce10ebce1bc95df26571bca8cb4636cf7a4ba71c1f893731f8e3de
7
- data.tar.gz: 212f1e3dfa7f3de2d928214c68d96fa0253f9a9f4e87154848772dcb139a3adb8f62f224713196ef32f77742a7e327eee7eca2a46442df9b4ed2f15c8d38cb3d
6
+ metadata.gz: 1ebfcad27fdbf3b80067629dc4ab04c54bf59ab5167b1a8755356e67ebf17ebc9b3b8053a827258f929fbb06cbc4e90ec5393f750bba8c46db1cc0d3945ba607
7
+ data.tar.gz: a8d0969fee54980e33627d707b577c70ca0fe10ff2e619012b40a7ae084fe2e8f0c9ba3afd82f16ffce1dd7686f587c6b29269d36d3d32a4bafcc7894e04a09e
data/.travis.yml CHANGED
@@ -1,4 +1,6 @@
1
1
  rvm:
2
2
  - 1.9.3
3
3
  - 2.0.0
4
-
4
+ env:
5
+ - rails='~> 3.2'
6
+ - rails='~> 4.0'
data/Gemfile CHANGED
@@ -2,6 +2,9 @@ source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
+ ENV['rails'] ||= '~> 4.0'
6
+ gem "rails", ENV['rails']
7
+
5
8
  group :development do
6
9
  gem "pry"
7
10
  gem "rspec"
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency "activerecord", ">= 3.0.0", '< 4'
22
- spec.add_runtime_dependency "activesupport", ">= 3.0.0", '< 4'
21
+ spec.add_runtime_dependency "activerecord", ">= 3.2"
22
+ spec.add_runtime_dependency "activesupport", ">= 3.2"
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
24
  spec.add_development_dependency "rake"
25
25
  end
@@ -1,3 +1,3 @@
1
1
  module DefaultValues
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -45,19 +45,11 @@ module DefaultValues
45
45
  define_method(:initialize_with_default_values) do |*attributes, &inner_block|
46
46
  defaults = defaults.merge(block.call) if block_given?
47
47
  defaults = Hash[defaults.each_pair.map{ |key, value| [key, value.kind_of?(Proc) ? value.call : value]}]
48
- authorizer = self.mass_assignment_authorizer(nil)
49
48
 
50
- parted_defaults = defaults.partition do |key, value|
51
- authorizer.deny?(key)
52
- end
53
-
54
- sanitized_defaults = Hash[parted_defaults[1]]
55
- protected_defaults = Hash[parted_defaults[0]]
56
-
57
- attributes[0] = sanitized_defaults.merge(attributes.first || {})
58
49
  initialize_without_default_values(*attributes, &inner_block)
59
- protected_defaults.each_pair do |key, value|
60
- self.send("#{key}=", value)
50
+
51
+ defaults.each_pair do |key, value|
52
+ write_attribute(key, value) unless attribute_present?(key)
61
53
  end
62
54
  end
63
55
 
@@ -1,14 +1,14 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  class Book < ActiveRecord::Base
4
- attr_protected :edition
4
+ attr_protected :edition if Rails.version.to_i < 4
5
5
 
6
6
  default_values price: 0, edition: 1, released_at: lambda { Time.now }
7
7
  end
8
8
 
9
9
  class Book2 < ActiveRecord::Base
10
10
  self.table_name = :books
11
- attr_protected :edition
11
+ attr_protected :edition if Rails.version.to_i < 4
12
12
  default_values price: 0, edition: 1 do
13
13
  t = Time.now
14
14
  {:released_at => t }
@@ -17,17 +17,16 @@ end
17
17
 
18
18
  class Book3 < ActiveRecord::Base
19
19
  self.table_name = :books
20
- attr_accessible :price
20
+ attr_accessible :price if Rails.version.to_i < 4
21
21
  default_values price: 0, edition: 1, released_at: -> { Time.now }
22
22
  end
23
23
 
24
24
  describe "ArDefaultValues" do
25
+ let!(:now) { Time.at(Time.now.to_i) }
26
+
25
27
  subject { @sample }
26
28
  describe :fixed_default_values do
27
- before do
28
- @now = Time.at(Time.now.to_i)
29
- Time.stub(:now).and_return(@now)
30
- end
29
+ before { Time.stub(:now) { now } }
31
30
  context :without_attributes do
32
31
  before do
33
32
  @sample = Book.new
@@ -35,7 +34,7 @@ describe "ArDefaultValues" do
35
34
  its(:title) { should be_nil }
36
35
  its(:price) { should == 0 }
37
36
  its(:edition) { should == 1 }
38
- its(:released_at) { should == @now }
37
+ its(:released_at) { should == now }
39
38
  end
40
39
  context :with_attributes do
41
40
  before do
@@ -44,7 +43,7 @@ describe "ArDefaultValues" do
44
43
  its(:title) { should be_nil }
45
44
  its(:price) { should == 100 }
46
45
  its(:edition) { should == 1 }
47
- its(:released_at) { should == @now }
46
+ its(:released_at) { should == now }
48
47
  end
49
48
  context :with_block do
50
49
  before do
@@ -55,17 +54,19 @@ describe "ArDefaultValues" do
55
54
  its(:title) { should == 'foo' }
56
55
  its(:price) { should == 0 }
57
56
  its(:edition) { should == 1 }
58
- its(:released_at) { should == @now }
57
+ its(:released_at) { should == now }
59
58
  end
60
59
 
61
- context :consider_attr_protected do
62
- before do
63
- @sample = Book.new(:edition => 3)
60
+ if Rails.version.to_i < 4
61
+ context :consider_attr_protected do
62
+ before do
63
+ @sample = Book.new(:edition => 3)
64
+ end
65
+ its(:title) { should be_nil }
66
+ its(:price) { should == 0 }
67
+ its(:edition) { should == 1 }
68
+ its(:released_at) { should == now }
64
69
  end
65
- its(:title) { should be_nil }
66
- its(:price) { should == 0 }
67
- its(:edition) { should == 1 }
68
- its(:released_at) { should == @now }
69
70
  end
70
71
  end
71
72
 
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'rspec'
4
+ require 'rails'
4
5
  require 'ar_default_values'
5
6
 
6
7
  # Requires supporting files with custom matchers and macros, etc,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar_default_values
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - masarakki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-18 00:00:00.000000000 Z
11
+ date: 2013-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,40 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: 3.0.0
20
- - - <
21
- - !ruby/object:Gem::Version
22
- version: '4'
19
+ version: '3.2'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - '>='
28
25
  - !ruby/object:Gem::Version
29
- version: 3.0.0
30
- - - <
31
- - !ruby/object:Gem::Version
32
- version: '4'
26
+ version: '3.2'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: activesupport
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
31
  - - '>='
38
32
  - !ruby/object:Gem::Version
39
- version: 3.0.0
40
- - - <
41
- - !ruby/object:Gem::Version
42
- version: '4'
33
+ version: '3.2'
43
34
  type: :runtime
44
35
  prerelease: false
45
36
  version_requirements: !ruby/object:Gem::Requirement
46
37
  requirements:
47
38
  - - '>='
48
39
  - !ruby/object:Gem::Version
49
- version: 3.0.0
50
- - - <
51
- - !ruby/object:Gem::Version
52
- version: '4'
40
+ version: '3.2'
53
41
  - !ruby/object:Gem::Dependency
54
42
  name: bundler
55
43
  requirement: !ruby/object:Gem::Requirement