traka 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,8 +3,8 @@ require 'test_helper'
3
3
  class IsTrakableTest < Test::Unit::TestCase
4
4
 
5
5
  def setup
6
- TrakaChange.destroy_all
7
- TrakaChange.set_version!(1)
6
+ Traka::Change.destroy_all
7
+ Traka::Change.set_version!(1)
8
8
  end
9
9
 
10
10
  def test_a_products_traka_uuid_should_be_uuid
@@ -34,7 +34,7 @@ class IsTrakableTest < Test::Unit::TestCase
34
34
  def test_a_product_should_record_changes_on_create
35
35
  c = Product.new(:name => "Product B")
36
36
  c.save
37
- tc = TrakaChange.last
37
+ tc = Traka::Change.last
38
38
 
39
39
  assert_equal tc.klass, "Product"
40
40
  assert_equal tc.action_type, "create"
@@ -44,7 +44,7 @@ class IsTrakableTest < Test::Unit::TestCase
44
44
  c = Product.new(:name => "Product B")
45
45
  c.save
46
46
  c.destroy
47
- tc = TrakaChange.last
47
+ tc = Traka::Change.last
48
48
 
49
49
  assert_equal tc.klass, "Product"
50
50
  assert_equal tc.action_type, "destroy"
@@ -55,7 +55,7 @@ class IsTrakableTest < Test::Unit::TestCase
55
55
  c.save
56
56
  c.name = "New Name"
57
57
  c.save
58
- tc = TrakaChange.last
58
+ tc = Traka::Change.last
59
59
 
60
60
  assert_equal tc.klass, "Product"
61
61
  assert_equal tc.action_type, "update"
@@ -64,7 +64,7 @@ class IsTrakableTest < Test::Unit::TestCase
64
64
  def test_a_cheese_should_record_changes_on_create
65
65
  c = Cheese.new(:name => "Cheese B")
66
66
  c.save
67
- tc = TrakaChange.last
67
+ tc = Traka::Change.last
68
68
 
69
69
  assert_equal tc.klass, "Cheese"
70
70
  assert_equal tc.action_type, "create"
@@ -74,7 +74,7 @@ class IsTrakableTest < Test::Unit::TestCase
74
74
  c = Cheese.new(:name => "Cheese B")
75
75
  c.save
76
76
  c.destroy
77
- tc = TrakaChange.last
77
+ tc = Traka::Change.last
78
78
 
79
79
  assert_equal tc.klass, "Cheese"
80
80
  assert_equal tc.action_type, "destroy"
@@ -85,7 +85,7 @@ class IsTrakableTest < Test::Unit::TestCase
85
85
  c.save
86
86
  c.name = "New Name"
87
87
  c.save
88
- tc = TrakaChange.last
88
+ tc = Traka::Change.last
89
89
 
90
90
  assert_equal tc.klass, "Cheese"
91
91
  assert_equal tc.action_type, "update"
@@ -0,0 +1,158 @@
1
+ require 'test_helper'
2
+
3
+ class TrakaChangeTest < ActiveSupport::TestCase
4
+
5
+ def setup
6
+ Traka::Change.destroy_all
7
+ Traka::Change.set_version!(1)
8
+ end
9
+
10
+ test "TrakaChange has latest version" do
11
+ assert_equal Traka::Change.latest_version, 1
12
+ end
13
+
14
+ test "TrakaChange can publish new version" do
15
+ assert_equal Traka::Change.latest_version, 1
16
+
17
+ Traka::Change.publish_new_version!
18
+
19
+ assert_equal Traka::Change.latest_version, 2
20
+ end
21
+
22
+ test "TrakaChange can list staged changes" do
23
+ p = Product.create(:name => "Product A")
24
+ c = Cheese.create(:name => "Cheese A")
25
+
26
+ assert_equal Traka::Change.staged_changes.count, 2
27
+ assert_equal Traka::Change.staged_changes.first.klass, "Product"
28
+ assert_equal Traka::Change.staged_changes.last.klass, "Cheese"
29
+ end
30
+
31
+ test "TrakaChange can list changes from a particular version" do
32
+ p = Product.create(:name => "Product A")
33
+ c = Cheese.create(:name => "Cheese A")
34
+
35
+ assert_equal Traka::Change.staged_changes.count, 2
36
+
37
+ Traka::Change.publish_new_version!
38
+
39
+ p2 = Product.create(:name => "Product B")
40
+
41
+ assert_equal Traka::Change.staged_changes.count, 1
42
+ assert_equal Traka::Change.staged_changes.first.klass, "Product"
43
+
44
+ assert_equal Traka::Change.changes_from(1).count, 3
45
+ assert_equal Traka::Change.changes_from(1).map(&:klass), ["Product", "Cheese", "Product"]
46
+ assert_equal Traka::Change.changes_from(1).map(&:action_type), ["create", "create", "create"]
47
+ end
48
+
49
+ test "TrakaChange can list differing changes" do
50
+ p = Product.create(:name => "Product A")
51
+ c = Cheese.create(:name => "Cheese A")
52
+
53
+ Traka::Change.publish_new_version!
54
+
55
+ p.name = "New name"
56
+ p.save
57
+ c.destroy
58
+
59
+ assert_equal Traka::Change.staged_changes.count, 2
60
+ assert_equal Traka::Change.staged_changes.map(&:klass), ["Product", "Cheese"]
61
+ assert_equal Traka::Change.staged_changes.map(&:action_type), ["update", "destroy"]
62
+ end
63
+
64
+ test "TrakaChange can filter out obsolete create->destroy actions" do
65
+ p = Product.create(:name => "Product A")
66
+ c = Cheese.create(:name => "Cheese A")
67
+
68
+ p.destroy
69
+
70
+ assert_equal Traka::Change.staged_changes.count, 1
71
+ assert_equal Traka::Change.staged_changes.map(&:klass), ["Cheese"]
72
+ assert_equal Traka::Change.staged_changes.map(&:action_type), ["create"]
73
+ end
74
+
75
+ test "TrakaChange can filter out obsolete update->destroy actions" do
76
+ p = Product.create(:name => "Product A")
77
+ c = Cheese.create(:name => "Cheese A")
78
+
79
+ Traka::Change.publish_new_version!
80
+
81
+ p.name = "New name"
82
+ p.save
83
+ c.name = "New name"
84
+ c.save
85
+
86
+ p.destroy
87
+
88
+ assert_equal Traka::Change.staged_changes.count, 1
89
+ assert_equal Traka::Change.staged_changes.map(&:klass), ["Cheese"]
90
+ assert_equal Traka::Change.staged_changes.map(&:action_type), ["update"]
91
+ end
92
+
93
+ test "TrakaChange can filter out obsolete create->update actions" do
94
+ p = Product.create(:name => "Product A")
95
+ c = Cheese.create(:name => "Cheese A")
96
+
97
+ p.name = "New name"
98
+ p.save
99
+
100
+ p.name = "Another name"
101
+ p.save
102
+
103
+ assert_equal Traka::Change.staged_changes.count, 2
104
+ assert_equal Traka::Change.staged_changes.map(&:klass), ["Product", "Cheese"]
105
+ assert_equal Traka::Change.staged_changes.map(&:action_type), ["create", "create"]
106
+ end
107
+
108
+ test "TrakaChange can filter out obsolete update->update actions" do
109
+ p = Product.create(:name => "Product A")
110
+ c = Cheese.create(:name => "Cheese A")
111
+
112
+ Traka::Change.publish_new_version!
113
+
114
+ p.name = "New name"
115
+ p.save
116
+
117
+ p.name = "Another name"
118
+ p.save
119
+
120
+ p.name = "And another name"
121
+ p.save
122
+
123
+ c.name = "New name"
124
+ c.save
125
+
126
+ assert_equal Traka::Change.staged_changes.count, 2
127
+ assert_equal Traka::Change.staged_changes.map(&:klass), ["Product", "Cheese"]
128
+ assert_equal Traka::Change.staged_changes.map(&:action_type), ["update", "update"]
129
+ end
130
+
131
+ test "TrakaChange can give unabridged list of changes" do
132
+ p = Product.create(:name => "Product A")
133
+ c = Cheese.create(:name => "Cheese A")
134
+
135
+ p.name = "New name"
136
+ p.save
137
+
138
+ p.name = "Another name"
139
+ p.save
140
+
141
+ p.destroy
142
+ c.destroy
143
+
144
+ # Abridged version would be empty because destroys would cancel out creates.
145
+ assert_equal Traka::Change.staged_changes(false).count, 6
146
+ assert_equal Traka::Change.staged_changes(false).map(&:klass), ["Product", "Cheese", "Product", "Product", "Product", "Cheese"]
147
+ assert_equal Traka::Change.staged_changes(false).map(&:action_type), ["create", "create", "update", "update", "destroy", "destroy"]
148
+ end
149
+
150
+ test "TrakaChange can resolve AR objects" do
151
+ p = Product.create(:name => "Product A")
152
+ c = Cheese.create(:name => "Cheese A")
153
+
154
+ assert_equal Traka::Change.staged_changes.first.get_record, p
155
+ assert_equal Traka::Change.staged_changes.last.get_record, c
156
+ end
157
+
158
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: traka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
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: 2013-12-30 00:00:00.000000000 Z
12
+ date: 2014-01-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -51,10 +51,11 @@ extensions: []
51
51
  extra_rdoc_files: []
52
52
  files:
53
53
  - lib/traka/is_trakable.rb
54
+ - lib/traka/change.rb
54
55
  - lib/traka/version.rb
55
- - lib/traka/is_traka.rb
56
56
  - lib/generators/traka/install_generator.rb
57
57
  - lib/generators/traka/templates/public/system/api/version.txt
58
+ - lib/generators/traka/templates/migration.rb
58
59
  - lib/tasks/traka_tasks.rake
59
60
  - lib/traka.rb
60
61
  - lib/templates/active_record/model/model.rb
@@ -73,9 +74,9 @@ files:
73
74
  - test/dummy/public/favicon.ico
74
75
  - test/dummy/db/schema.rb
75
76
  - test/dummy/db/development.sqlite3
77
+ - test/dummy/db/migrate/20140102053940_create_traka_changes.rb
76
78
  - test/dummy/db/migrate/20131219051348_create_cheeses.rb
77
79
  - test/dummy/db/migrate/20131219051328_create_products.rb
78
- - test/dummy/db/migrate/20131227113858_create_traka_changes.rb
79
80
  - test/dummy/db/test.sqlite3
80
81
  - test/dummy/config/application.rb
81
82
  - test/dummy/config/environments/production.rb
@@ -94,23 +95,20 @@ files:
94
95
  - test/dummy/config/environment.rb
95
96
  - test/dummy/README.rdoc
96
97
  - test/dummy/script/rails
97
- - test/dummy/test/fixtures/traka_changes.yml
98
98
  - test/dummy/test/fixtures/cheeses.yml
99
99
  - test/dummy/test/fixtures/products.yml
100
100
  - test/dummy/test/unit/product_test.rb
101
101
  - test/dummy/test/unit/cheese_test.rb
102
- - test/dummy/test/unit/traka_change_test.rb
103
102
  - test/dummy/app/controllers/application_controller.rb
104
103
  - test/dummy/app/assets/stylesheets/application.css
105
104
  - test/dummy/app/assets/javascripts/application.js
106
105
  - test/dummy/app/helpers/application_helper.rb
107
106
  - test/dummy/app/views/layouts/application.html.erb
108
107
  - test/dummy/app/models/product.rb
109
- - test/dummy/app/models/traka_change.rb
110
108
  - test/dummy/app/models/cheese.rb
111
109
  - test/traka_test.rb
112
- - test/is_traka_test.rb
113
110
  - test/is_trakable_test.rb
111
+ - test/traka_change_test.rb
114
112
  homepage: http://github.com/buntine/traka
115
113
  licenses:
116
114
  - MIT
@@ -149,9 +147,9 @@ test_files:
149
147
  - test/dummy/public/favicon.ico
150
148
  - test/dummy/db/schema.rb
151
149
  - test/dummy/db/development.sqlite3
150
+ - test/dummy/db/migrate/20140102053940_create_traka_changes.rb
152
151
  - test/dummy/db/migrate/20131219051348_create_cheeses.rb
153
152
  - test/dummy/db/migrate/20131219051328_create_products.rb
154
- - test/dummy/db/migrate/20131227113858_create_traka_changes.rb
155
153
  - test/dummy/db/test.sqlite3
156
154
  - test/dummy/config/application.rb
157
155
  - test/dummy/config/environments/production.rb
@@ -170,20 +168,17 @@ test_files:
170
168
  - test/dummy/config/environment.rb
171
169
  - test/dummy/README.rdoc
172
170
  - test/dummy/script/rails
173
- - test/dummy/test/fixtures/traka_changes.yml
174
171
  - test/dummy/test/fixtures/cheeses.yml
175
172
  - test/dummy/test/fixtures/products.yml
176
173
  - test/dummy/test/unit/product_test.rb
177
174
  - test/dummy/test/unit/cheese_test.rb
178
- - test/dummy/test/unit/traka_change_test.rb
179
175
  - test/dummy/app/controllers/application_controller.rb
180
176
  - test/dummy/app/assets/stylesheets/application.css
181
177
  - test/dummy/app/assets/javascripts/application.js
182
178
  - test/dummy/app/helpers/application_helper.rb
183
179
  - test/dummy/app/views/layouts/application.html.erb
184
180
  - test/dummy/app/models/product.rb
185
- - test/dummy/app/models/traka_change.rb
186
181
  - test/dummy/app/models/cheese.rb
187
182
  - test/traka_test.rb
188
- - test/is_traka_test.rb
189
183
  - test/is_trakable_test.rb
184
+ - test/traka_change_test.rb
@@ -1,5 +0,0 @@
1
- class TrakaChange < ActiveRecord::Base
2
- attr_accessible :klass, :action_type, :uuid, :version
3
-
4
- is_traka
5
- end
@@ -1,13 +0,0 @@
1
- # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
-
3
- one:
4
- klass: MyString
5
- uuid: MyString
6
- action_type: MyString
7
- version: 1
8
-
9
- two:
10
- klass: MyString
11
- uuid: MyString
12
- action_type: MyString
13
- version: 1
@@ -1,7 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TrakaChangeTest < ActiveSupport::TestCase
4
- # test "the truth" do
5
- # assert true
6
- # end
7
- end
@@ -1,158 +0,0 @@
1
- require 'test_helper'
2
-
3
- class IsTrakaTest < ActiveSupport::TestCase
4
-
5
- def setup
6
- TrakaChange.destroy_all
7
- TrakaChange.set_version!(1)
8
- end
9
-
10
- test "TrakaChange has latest version" do
11
- assert_equal TrakaChange.latest_version, 1
12
- end
13
-
14
- test "TrakaChange can publish new version" do
15
- assert_equal TrakaChange.latest_version, 1
16
-
17
- TrakaChange.publish_new_version!
18
-
19
- assert_equal TrakaChange.latest_version, 2
20
- end
21
-
22
- test "TrakaChange can list staged changes" do
23
- p = Product.create(:name => "Product A")
24
- c = Cheese.create(:name => "Cheese A")
25
-
26
- assert_equal TrakaChange.staged_changes.count, 2
27
- assert_equal TrakaChange.staged_changes.first.klass, "Product"
28
- assert_equal TrakaChange.staged_changes.last.klass, "Cheese"
29
- end
30
-
31
- test "TrakaChange can list changes from a particular version" do
32
- p = Product.create(:name => "Product A")
33
- c = Cheese.create(:name => "Cheese A")
34
-
35
- assert_equal TrakaChange.staged_changes.count, 2
36
-
37
- TrakaChange.publish_new_version!
38
-
39
- p2 = Product.create(:name => "Product B")
40
-
41
- assert_equal TrakaChange.staged_changes.count, 1
42
- assert_equal TrakaChange.staged_changes.first.klass, "Product"
43
-
44
- assert_equal TrakaChange.changes_from(1).count, 3
45
- assert_equal TrakaChange.changes_from(1).map(&:klass), ["Product", "Cheese", "Product"]
46
- assert_equal TrakaChange.changes_from(1).map(&:action_type), ["create", "create", "create"]
47
- end
48
-
49
- test "TrakaChange can list differing changes" do
50
- p = Product.create(:name => "Product A")
51
- c = Cheese.create(:name => "Cheese A")
52
-
53
- TrakaChange.publish_new_version!
54
-
55
- p.name = "New name"
56
- p.save
57
- c.destroy
58
-
59
- assert_equal TrakaChange.staged_changes.count, 2
60
- assert_equal TrakaChange.staged_changes.map(&:klass), ["Product", "Cheese"]
61
- assert_equal TrakaChange.staged_changes.map(&:action_type), ["update", "destroy"]
62
- end
63
-
64
- test "TrakaChange can filter out obsolete create->destroy actions" do
65
- p = Product.create(:name => "Product A")
66
- c = Cheese.create(:name => "Cheese A")
67
-
68
- p.destroy
69
-
70
- assert_equal TrakaChange.staged_changes.count, 1
71
- assert_equal TrakaChange.staged_changes.map(&:klass), ["Cheese"]
72
- assert_equal TrakaChange.staged_changes.map(&:action_type), ["create"]
73
- end
74
-
75
- test "TrakaChange can filter out obsolete update->destroy actions" do
76
- p = Product.create(:name => "Product A")
77
- c = Cheese.create(:name => "Cheese A")
78
-
79
- TrakaChange.publish_new_version!
80
-
81
- p.name = "New name"
82
- p.save
83
- c.name = "New name"
84
- c.save
85
-
86
- p.destroy
87
-
88
- assert_equal TrakaChange.staged_changes.count, 1
89
- assert_equal TrakaChange.staged_changes.map(&:klass), ["Cheese"]
90
- assert_equal TrakaChange.staged_changes.map(&:action_type), ["update"]
91
- end
92
-
93
- test "TrakaChange can filter out obsolete create->update actions" do
94
- p = Product.create(:name => "Product A")
95
- c = Cheese.create(:name => "Cheese A")
96
-
97
- p.name = "New name"
98
- p.save
99
-
100
- p.name = "Another name"
101
- p.save
102
-
103
- assert_equal TrakaChange.staged_changes.count, 2
104
- assert_equal TrakaChange.staged_changes.map(&:klass), ["Product", "Cheese"]
105
- assert_equal TrakaChange.staged_changes.map(&:action_type), ["create", "create"]
106
- end
107
-
108
- test "TrakaChange can filter out obsolete update->update actions" do
109
- p = Product.create(:name => "Product A")
110
- c = Cheese.create(:name => "Cheese A")
111
-
112
- TrakaChange.publish_new_version!
113
-
114
- p.name = "New name"
115
- p.save
116
-
117
- p.name = "Another name"
118
- p.save
119
-
120
- p.name = "And another name"
121
- p.save
122
-
123
- c.name = "New name"
124
- c.save
125
-
126
- assert_equal TrakaChange.staged_changes.count, 2
127
- assert_equal TrakaChange.staged_changes.map(&:klass), ["Product", "Cheese"]
128
- assert_equal TrakaChange.staged_changes.map(&:action_type), ["update", "update"]
129
- end
130
-
131
- test "TrakaChange can give unabridged list of changes" do
132
- p = Product.create(:name => "Product A")
133
- c = Cheese.create(:name => "Cheese A")
134
-
135
- p.name = "New name"
136
- p.save
137
-
138
- p.name = "Another name"
139
- p.save
140
-
141
- p.destroy
142
- c.destroy
143
-
144
- # Abridged version would be empty because destroys would cancel out creates.
145
- assert_equal TrakaChange.staged_changes(false).count, 6
146
- assert_equal TrakaChange.staged_changes(false).map(&:klass), ["Product", "Cheese", "Product", "Product", "Product", "Cheese"]
147
- assert_equal TrakaChange.staged_changes(false).map(&:action_type), ["create", "create", "update", "update", "destroy", "destroy"]
148
- end
149
-
150
- test "TrakaChange can resolve AR objects" do
151
- p = Product.create(:name => "Product A")
152
- c = Cheese.create(:name => "Cheese A")
153
-
154
- assert_equal TrakaChange.staged_changes.first.get_record, p
155
- assert_equal TrakaChange.staged_changes.last.get_record, c
156
- end
157
-
158
- end