delta_changes 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f722d8be9e14ffadad47521a4db8ddab44a35300
4
+ data.tar.gz: 7eae375050f5af8f4090ce310a0205b114e292a7
5
+ SHA512:
6
+ metadata.gz: 299ca74a9af437f53bb81c32a2d227add2c587e0dc282c5af18bc471d2fea7d9538185805af6d926749bea120cc3961b48bb48111b09ba08e8e5269ca082d859
7
+ data.tar.gz: d9cbf8b6ba85d2bb8bd7b6c35d96d3ca0c8182eb8adbb6ee4e2def43392a561b46826bb28263b4725aec0fa273dc677e3ceedca8150a21f3ccb0209512db0e95
@@ -6,7 +6,8 @@ module DeltaChanges
6
6
  base.extend(ClassMethods)
7
7
  base.cattr_accessor :delta_changes_options
8
8
  base.attribute_method_suffix '_delta_changed?', '_delta_change', '_delta_was', '_delta_will_change!'
9
- base.alias_method_chain :write_attribute, :delta_changes
9
+ base.send(:alias_method, :write_attribute_without_delta_changes, :write_attribute)
10
+ base.send(:alias_method, :write_attribute, :write_attribute_with_delta_changes)
10
11
  end
11
12
 
12
13
  module ClassMethods
@@ -20,23 +21,23 @@ module DeltaChanges
20
21
  #
21
22
  def define_virtual_attribute_delta_methods
22
23
  delta_changes_options[:attributes].each do |tracked_attribute|
23
- class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
24
- def #{tracked_attribute}_delta_changed?
25
- attribute_delta_changed?('#{tracked_attribute}')
24
+ class_eval do
25
+ define_method("#{tracked_attribute}_delta_changed?") do
26
+ attribute_delta_changed?(tracked_attribute)
26
27
  end
27
28
 
28
- def #{tracked_attribute}_delta_change
29
- attribute_delta_change('#{tracked_attribute}')
29
+ define_method("#{tracked_attribute}_delta_change") do
30
+ attribute_delta_change(tracked_attribute)
30
31
  end
31
32
 
32
- def #{tracked_attribute}_delta_was
33
- attribute_delta_was('#{tracked_attribute}')
33
+ define_method("#{tracked_attribute}_delta_was") do
34
+ attribute_delta_was(tracked_attribute)
34
35
  end
35
36
 
36
- def #{tracked_attribute}_delta_will_change!
37
- attribute_delta_will_change!('#{tracked_attribute}')
37
+ define_method("#{tracked_attribute}_delta_will_change!") do
38
+ attribute_delta_will_change!(tracked_attribute)
38
39
  end
39
- RUBY
40
+ end
40
41
  end
41
42
  end
42
43
  end
@@ -92,23 +93,31 @@ module DeltaChanges
92
93
  def write_attribute_with_delta_changes(attr, value)
93
94
  attr = attr.to_s
94
95
 
95
- if self.class.delta_changes_options[:columns].include?(attr)
96
- # The attribute already has an unsaved change.
97
- if delta_changed_attributes.include?(attr)
98
- old = delta_changed_attributes[attr]
99
- delta_changed_attributes.delete(attr) unless delta_changes_field_changed?(attr, old, value)
100
- else
101
- old = clone_attribute_value(:read_attribute, attr)
102
- delta_changed_attributes[attr] = old if delta_changes_field_changed?(attr, old, value)
103
- end
96
+ unless self.class.delta_changes_options[:columns].include?(attr)
97
+ return write_attribute_without_delta_changes(attr, value)
104
98
  end
105
99
 
106
- write_attribute_without_delta_changes(attr, value)
100
+ # The attribute already has an unsaved change.
101
+ if delta_changed_attributes.include?(attr)
102
+ old = delta_changed_attributes[attr]
103
+ write_attribute_without_delta_changes(attr, value)
104
+ delta_changed_attributes.delete(attr) unless delta_changes_field_changed?(attr, old, value)
105
+ else
106
+ old = clone_attribute_value(:read_attribute, attr)
107
+ write_attribute_without_delta_changes(attr, value)
108
+ delta_changed_attributes[attr] = old if delta_changes_field_changed?(attr, old, value)
109
+ end
107
110
  end
108
111
 
109
112
  def delta_changes_field_changed?(attr, old, value)
110
- @delta_changes_field_changed ||= defined?(field_changed?)
111
- @delta_changes_field_changed ? field_changed?(attr, old, value) : _field_changed?(attr, old, value) # rails 3.0-3.1 vs 3.2
113
+ return true if old.nil? && !value.nil?
114
+ if ActiveRecord::VERSION::STRING < '4.2.0'
115
+ _field_changed?(attr, old, value)
116
+ elsif ActiveRecord::VERSION::MAJOR < 5
117
+ _field_changed?(attr, old)
118
+ else
119
+ changes_include?(attr)
120
+ end
112
121
  end
113
122
  end
114
123
  end
@@ -1,3 +1,3 @@
1
1
  module DeltaChanges
2
- VERSION = "1.0.0"
2
+ VERSION = "2.0.0"
3
3
  end
metadata CHANGED
@@ -1,30 +1,117 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delta_changes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 2.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Michael Grosser
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-07 00:00:00.000000000 Z
11
+ date: 2016-03-10 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
- version: '0'
19
+ version: 3.2.22
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.1'
22
23
  type: :runtime
23
24
  prerelease: false
24
25
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
26
  requirements:
27
- - - ! '>='
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.22
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.1'
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: sqlite3
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: bump
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: wwtd
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: byebug
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
28
115
  - !ruby/object:Gem::Version
29
116
  version: '0'
30
117
  description:
@@ -33,54 +120,30 @@ executables: []
33
120
  extensions: []
34
121
  extra_rdoc_files: []
35
122
  files:
36
- - .travis.yml
37
- - Appraisals
38
- - Gemfile
39
- - Gemfile.lock
40
- - Rakefile
41
- - Readme.md
42
- - delta_changes.gemspec
43
- - gemfiles/rails23.gemfile
44
- - gemfiles/rails23.gemfile.lock
45
- - gemfiles/rails30.gemfile
46
- - gemfiles/rails30.gemfile.lock
47
- - gemfiles/rails31.gemfile
48
- - gemfiles/rails31.gemfile.lock
49
- - gemfiles/rails32.gemfile
50
- - gemfiles/rails32.gemfile.lock
51
123
  - lib/delta_changes.rb
52
124
  - lib/delta_changes/version.rb
53
- - spec/delta_changes_spec.rb
54
- - spec/spec_helper.rb
55
125
  homepage: http://github.com/grosser/delta_changes
56
126
  licenses:
57
127
  - MIT
128
+ metadata: {}
58
129
  post_install_message:
59
130
  rdoc_options: []
60
131
  require_paths:
61
132
  - lib
62
133
  required_ruby_version: !ruby/object:Gem::Requirement
63
- none: false
64
134
  requirements:
65
- - - ! '>='
135
+ - - ">="
66
136
  - !ruby/object:Gem::Version
67
137
  version: '0'
68
- segments:
69
- - 0
70
- hash: -171365277466758643
71
138
  required_rubygems_version: !ruby/object:Gem::Requirement
72
- none: false
73
139
  requirements:
74
- - - ! '>='
140
+ - - ">="
75
141
  - !ruby/object:Gem::Version
76
142
  version: '0'
77
- segments:
78
- - 0
79
- hash: -171365277466758643
80
143
  requirements: []
81
144
  rubyforge_project:
82
- rubygems_version: 1.8.25
145
+ rubygems_version: 2.4.5.1
83
146
  signing_key:
84
- specification_version: 3
147
+ specification_version: 4
85
148
  summary: Additional real/virtual attribute change tracking independent of ActiveRecords
86
149
  test_files: []
@@ -1,4 +0,0 @@
1
- rvm:
2
- - ree
3
- - 1.9.3
4
- - 2.0.0
data/Appraisals DELETED
@@ -1,5 +0,0 @@
1
- ["2.3.18", "3.0.20", "3.1.12", "3.2.13"].each do |version|
2
- appraise "rails#{version[0..2].sub(".","")}" do
3
- gem 'activerecord', version
4
- end
5
- end
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- source "https://rubygems.org"
2
- gemspec
3
-
4
- gem "appraisal"
5
- gem "rake"
6
- gem "rspec", "~>2"
7
- gem "sqlite3"
8
- gem "bump"
@@ -1,51 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- delta_changes (1.0.0)
5
- activerecord
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activemodel (3.2.13)
11
- activesupport (= 3.2.13)
12
- builder (~> 3.0.0)
13
- activerecord (3.2.13)
14
- activemodel (= 3.2.13)
15
- activesupport (= 3.2.13)
16
- arel (~> 3.0.2)
17
- tzinfo (~> 0.3.29)
18
- activesupport (3.2.13)
19
- i18n (= 0.6.1)
20
- multi_json (~> 1.0)
21
- appraisal (0.5.2)
22
- bundler
23
- rake
24
- arel (3.0.2)
25
- builder (3.0.4)
26
- bump (0.4.2)
27
- diff-lcs (1.1.3)
28
- i18n (0.6.1)
29
- multi_json (1.7.6)
30
- rake (10.0.4)
31
- rspec (2.6.0)
32
- rspec-core (~> 2.6.0)
33
- rspec-expectations (~> 2.6.0)
34
- rspec-mocks (~> 2.6.0)
35
- rspec-core (2.6.4)
36
- rspec-expectations (2.6.0)
37
- diff-lcs (~> 1.1.2)
38
- rspec-mocks (2.6.0)
39
- sqlite3 (1.3.6)
40
- tzinfo (0.3.37)
41
-
42
- PLATFORMS
43
- ruby
44
-
45
- DEPENDENCIES
46
- appraisal
47
- bump
48
- delta_changes!
49
- rake
50
- rspec (~> 2)
51
- sqlite3
data/Rakefile DELETED
@@ -1,12 +0,0 @@
1
- require "bundler/setup"
2
- require "bundler/gem_tasks"
3
- require "appraisal"
4
- require "bump/tasks"
5
-
6
- task :spec do
7
- sh "rspec spec/"
8
- end
9
-
10
- task :default do
11
- sh "rake appraisal:install && rake appraisal spec"
12
- end
data/Readme.md DELETED
@@ -1,34 +0,0 @@
1
- Additional real/virtual attribute change tracking independent of ActiveRecords
2
-
3
-
4
- Install
5
- =======
6
-
7
- gem install delta_changes
8
-
9
- Usage
10
- =====
11
-
12
- class User < ActiveRecord::Base
13
- include DeltaChanges::Extension
14
- delta_changes :columns => [:name], :attributes => [:full_name]
15
- end
16
-
17
- user.name = "bar"
18
- user.delta_changes # => {"name" => [nil, "bar"]}
19
-
20
- user.full_name_will_change!
21
- user.delta_changes # => {"name" => [nil, "bar"], "full_name" => [nil, "Mr. Bar"]}
22
-
23
- user.save!
24
- user.delta_changes # => {"name" => [nil, "bar"], "full_name" => [nil, "Mr. Bar"]}
25
-
26
- user.reset_delta_changes!
27
- user.delta_changes # => {}
28
-
29
- Author
30
- ======
31
- [Michael Grosser](http://grosser.it)<br/>
32
- michael@grosser.it<br/>
33
- License: MIT<br/>
34
- [![Build Status](https://secure.travis-ci.org/grosser/delta_changes.png)](http://travis-ci.org/grosser/delta_changes)
@@ -1,13 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
- name = "delta_changes"
3
- require "#{name}/version"
4
-
5
- Gem::Specification.new name, DeltaChanges::VERSION do |s|
6
- s.summary = "Additional real/virtual attribute change tracking independent of ActiveRecords"
7
- s.authors = ["Michael Grosser"]
8
- s.email = "michael@grosser.it"
9
- s.homepage = "http://github.com/grosser/#{name}"
10
- s.files = `git ls-files`.split("\n")
11
- s.add_runtime_dependency "activerecord"
12
- s.license = "MIT"
13
- end
@@ -1,12 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "appraisal"
6
- gem "rake"
7
- gem "rspec", "~>2"
8
- gem "sqlite3"
9
- gem "bump"
10
- gem "activerecord", "2.3.18"
11
-
12
- gemspec :path=>"../"
@@ -1,39 +0,0 @@
1
- PATH
2
- remote: /Users/mgrosser/code/tools/delta_changes
3
- specs:
4
- delta_changes (0.0.1)
5
- activerecord
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activerecord (2.3.18)
11
- activesupport (= 2.3.18)
12
- activesupport (2.3.18)
13
- appraisal (0.5.2)
14
- bundler
15
- rake
16
- bump (0.4.2)
17
- diff-lcs (1.2.4)
18
- rake (10.0.4)
19
- rspec (2.13.0)
20
- rspec-core (~> 2.13.0)
21
- rspec-expectations (~> 2.13.0)
22
- rspec-mocks (~> 2.13.0)
23
- rspec-core (2.13.1)
24
- rspec-expectations (2.13.0)
25
- diff-lcs (>= 1.1.3, < 2.0)
26
- rspec-mocks (2.13.1)
27
- sqlite3 (1.3.7)
28
-
29
- PLATFORMS
30
- ruby
31
-
32
- DEPENDENCIES
33
- activerecord (= 2.3.18)
34
- appraisal
35
- bump
36
- delta_changes!
37
- rake
38
- rspec (~> 2)
39
- sqlite3
@@ -1,12 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "appraisal"
6
- gem "rake"
7
- gem "rspec", "~>2"
8
- gem "sqlite3"
9
- gem "bump"
10
- gem "activerecord", "3.0.20"
11
-
12
- gemspec :path=>"../"
@@ -1,50 +0,0 @@
1
- PATH
2
- remote: /Users/mgrosser/code/tools/delta_changes
3
- specs:
4
- delta_changes (0.0.1)
5
- activerecord
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activemodel (3.0.20)
11
- activesupport (= 3.0.20)
12
- builder (~> 2.1.2)
13
- i18n (~> 0.5.0)
14
- activerecord (3.0.20)
15
- activemodel (= 3.0.20)
16
- activesupport (= 3.0.20)
17
- arel (~> 2.0.10)
18
- tzinfo (~> 0.3.23)
19
- activesupport (3.0.20)
20
- appraisal (0.5.2)
21
- bundler
22
- rake
23
- arel (2.0.10)
24
- builder (2.1.2)
25
- bump (0.4.2)
26
- diff-lcs (1.2.4)
27
- i18n (0.5.0)
28
- rake (10.0.4)
29
- rspec (2.13.0)
30
- rspec-core (~> 2.13.0)
31
- rspec-expectations (~> 2.13.0)
32
- rspec-mocks (~> 2.13.0)
33
- rspec-core (2.13.1)
34
- rspec-expectations (2.13.0)
35
- diff-lcs (>= 1.1.3, < 2.0)
36
- rspec-mocks (2.13.1)
37
- sqlite3 (1.3.7)
38
- tzinfo (0.3.37)
39
-
40
- PLATFORMS
41
- ruby
42
-
43
- DEPENDENCIES
44
- activerecord (= 3.0.20)
45
- appraisal
46
- bump
47
- delta_changes!
48
- rake
49
- rspec (~> 2)
50
- sqlite3
@@ -1,12 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "appraisal"
6
- gem "rake"
7
- gem "rspec", "~>2"
8
- gem "sqlite3"
9
- gem "bump"
10
- gem "activerecord", "3.1.12"
11
-
12
- gemspec :path=>"../"
@@ -1,52 +0,0 @@
1
- PATH
2
- remote: /Users/mgrosser/code/tools/delta_changes
3
- specs:
4
- delta_changes (0.0.1)
5
- activerecord
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activemodel (3.1.12)
11
- activesupport (= 3.1.12)
12
- builder (~> 3.0.0)
13
- i18n (~> 0.6)
14
- activerecord (3.1.12)
15
- activemodel (= 3.1.12)
16
- activesupport (= 3.1.12)
17
- arel (~> 2.2.3)
18
- tzinfo (~> 0.3.29)
19
- activesupport (3.1.12)
20
- multi_json (~> 1.0)
21
- appraisal (0.5.2)
22
- bundler
23
- rake
24
- arel (2.2.3)
25
- builder (3.0.4)
26
- bump (0.4.2)
27
- diff-lcs (1.2.4)
28
- i18n (0.6.4)
29
- multi_json (1.7.6)
30
- rake (10.0.4)
31
- rspec (2.13.0)
32
- rspec-core (~> 2.13.0)
33
- rspec-expectations (~> 2.13.0)
34
- rspec-mocks (~> 2.13.0)
35
- rspec-core (2.13.1)
36
- rspec-expectations (2.13.0)
37
- diff-lcs (>= 1.1.3, < 2.0)
38
- rspec-mocks (2.13.1)
39
- sqlite3 (1.3.7)
40
- tzinfo (0.3.37)
41
-
42
- PLATFORMS
43
- ruby
44
-
45
- DEPENDENCIES
46
- activerecord (= 3.1.12)
47
- appraisal
48
- bump
49
- delta_changes!
50
- rake
51
- rspec (~> 2)
52
- sqlite3
@@ -1,12 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "appraisal"
6
- gem "rake"
7
- gem "rspec", "~>2"
8
- gem "sqlite3"
9
- gem "bump"
10
- gem "activerecord", "3.2.13"
11
-
12
- gemspec :path=>"../"
@@ -1,52 +0,0 @@
1
- PATH
2
- remote: /Users/mgrosser/code/tools/delta_changes
3
- specs:
4
- delta_changes (0.0.1)
5
- activerecord
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activemodel (3.2.13)
11
- activesupport (= 3.2.13)
12
- builder (~> 3.0.0)
13
- activerecord (3.2.13)
14
- activemodel (= 3.2.13)
15
- activesupport (= 3.2.13)
16
- arel (~> 3.0.2)
17
- tzinfo (~> 0.3.29)
18
- activesupport (3.2.13)
19
- i18n (= 0.6.1)
20
- multi_json (~> 1.0)
21
- appraisal (0.5.2)
22
- bundler
23
- rake
24
- arel (3.0.2)
25
- builder (3.0.4)
26
- bump (0.4.2)
27
- diff-lcs (1.2.4)
28
- i18n (0.6.1)
29
- multi_json (1.7.6)
30
- rake (10.0.4)
31
- rspec (2.13.0)
32
- rspec-core (~> 2.13.0)
33
- rspec-expectations (~> 2.13.0)
34
- rspec-mocks (~> 2.13.0)
35
- rspec-core (2.13.1)
36
- rspec-expectations (2.13.0)
37
- diff-lcs (>= 1.1.3, < 2.0)
38
- rspec-mocks (2.13.1)
39
- sqlite3 (1.3.7)
40
- tzinfo (0.3.37)
41
-
42
- PLATFORMS
43
- ruby
44
-
45
- DEPENDENCIES
46
- activerecord (= 3.2.13)
47
- appraisal
48
- bump
49
- delta_changes!
50
- rake
51
- rspec (~> 2)
52
- sqlite3
@@ -1,99 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe DeltaChanges do
4
- it "has a VERSION" do
5
- DeltaChanges::VERSION.should =~ /^[\.\da-z]+$/
6
- end
7
-
8
- it "should not create methods on unspecified attributes" do
9
- # TODO broken, but that might be rails 2 ...
10
- #expect{
11
- # User.new.email_delta_will_change!
12
- #}.to raise_error
13
-
14
- expect{
15
- User.new.bar_delta_will_change!
16
- }.to raise_error
17
-
18
- expect{
19
- User.new.does_not_exist_delta_will_change!
20
- }.to raise_error
21
- end
22
-
23
- describe "#delta_changes" do
24
- it "should be empty on unchanged" do
25
- User.new.delta_changes.should == {}
26
- end
27
-
28
- it "should be filled by tracked column changes" do
29
- User.new(:name => "Peter").delta_changes.should == {"name"=>[nil, "Peter"]}
30
- end
31
-
32
- it "should be filled by tracked number column change" do
33
- User.new(:score => 5).delta_changes.should == {"score"=>[nil, 5]}
34
- end
35
-
36
- it "should be filled by tracked number column change that have the wrong type" do
37
- User.new(:score => "5").delta_changes.should == {"score"=>[nil, 5]}
38
- end
39
-
40
- it "should not be filled by untracked column changes" do
41
- User.new(:email => "Peter").delta_changes.should == {}
42
- end
43
-
44
- it "should not be filled implicit tracked attribute changes" do
45
- user = User.new(:foo => 1)
46
- user.delta_changes.should == {}
47
- end
48
-
49
- it "should be filled by explicit tracked attribute changes" do
50
- user = User.new(:foo => 1)
51
- user.foo_delta_will_change!
52
- user.foo = 2
53
- user.delta_changes.should == {"foo"=>[1, 2]}
54
- end
55
-
56
- it "should not mess with normal changes" do
57
- User.new(:email => "EMAIL", :name => "NAME", :foo => "FOO").changes.should ==
58
- {"email"=>[nil, "EMAIL"], "name"=>[nil, "NAME"]}
59
- end
60
-
61
- it "should not reset columns on save" do
62
- user = User.create!(:name => "NAME", :foo => "FOO", :bar => "BAR")
63
- user.delta_changes.should == {"name"=>[nil, "NAME"]}
64
- end
65
-
66
- it "should not reset columns on update" do
67
- user = User.create!(:name => "NAME", :foo => "FOO", :bar => "BAR")
68
- user.update_attributes(:name => "NAME-2")
69
- user.delta_changes.should == {"name"=>[nil, "NAME-2"]}
70
- end
71
-
72
- # that might change, I'd consider this a bug ... but just documenting for now
73
- it "should not reset columns on reload" do
74
- user = User.create!(:name => "NAME", :foo => "FOO", :bar => "BAR")
75
- user.reload
76
- user.delta_changes.should == {"name"=>[nil, "NAME"]}
77
- end
78
-
79
- it "should have previouse value from db" do
80
- user = User.create!(:name => "NAME", :foo => "FOO", :bar => "BAR")
81
- user = User.find(user)
82
- user.name = "NAME-2"
83
- user.delta_changes.should == {"name"=>["NAME", "NAME-2"]}
84
- end
85
-
86
- it "should not track non-changes on tracked columns" do
87
- user = User.create!(:score => 5).reload
88
- user.reset_delta_changes!
89
-
90
- user.delta_changes.should == {}
91
-
92
- user.score = 5
93
- user.delta_changes.should == {}
94
-
95
- user.score = "5"
96
- user.delta_changes.should == {}
97
- end
98
- end
99
- end
@@ -1,31 +0,0 @@
1
- require "bundler/setup"
2
- require "delta_changes"
3
- require "active_record"
4
-
5
- # connect
6
- ActiveRecord::Base.establish_connection(
7
- :adapter => "sqlite3",
8
- :database => ":memory:"
9
- )
10
-
11
- # create tables
12
- ActiveRecord::Schema.define(:version => 1) do
13
- create_table :users do |t|
14
- t.string :name
15
- t.string :email
16
- t.integer :score
17
- t.timestamps
18
- end
19
- end
20
-
21
- # create models
22
- class User < ActiveRecord::Base
23
- include DeltaChanges::Extension
24
- attr_accessor :foo, :bar
25
-
26
- delta_changes :columns => ["name", "score"], :attributes => ["foo"]
27
-
28
- def full_name
29
- "Mr. #{name}"
30
- end
31
- end