memento 0.4.3 → 0.5.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
- SHA1:
3
- metadata.gz: a398d1db995dde129200972e15977dd8e7988b81
4
- data.tar.gz: 6ead2aab247ffbe93318efc279a84ab0f4b6023e
2
+ SHA256:
3
+ metadata.gz: 0ffb4f13c2e20305cc1278a65fddde559e090748407cf824316e65aa23ff2c7e
4
+ data.tar.gz: 60c42b17605cf297072f936f096f7d7cc539252338df1cf44d84a4cf87cb32ec
5
5
  SHA512:
6
- metadata.gz: b2e302f650ed080fabd0807fdaeb6d73aa3d60836dec5f7ef6a5aacddca58f32191e2e66d4006a5950ca92fb79787216be1cce48d6a2d37551f16996a8ee7461
7
- data.tar.gz: 985907459e9ec2f51a4fb847e317f5872195bdfeee31038a1ec4de8e9e2c7e5bb3dfecfa793e33460ec781d5218b68a9e54bc314396a0db396701f007a7aaa30
6
+ metadata.gz: 50c98b769d00c6433da06824e1f9d46e17b9a5011d896dee58c9b973bbb3b3369cf133d4fac829ee666f98b41c6b05088d139246cb14b45cd5b5a30c54f6a6e1
7
+ data.tar.gz: 04f573dd73bbdf067882ce76bde3e3e745918d3ec14676cabbe3a197d9921239faede0823104f77f4eacfb6a881d1d4f3092ec13871b7cdaa0316cf9096cab2e
data/.gitignore CHANGED
@@ -4,4 +4,5 @@ coverage
4
4
  rdoc
5
5
  pkg
6
6
  .rvmrc
7
+ .ruby-version
7
8
  Gemfile.lock
data/CHANGES.md CHANGED
@@ -1,6 +1,13 @@
1
1
  ### dev
2
2
 
3
- [full changelog](http://github.com/yolk/valvat/compare/v0.4.3...master)
3
+ [full changelog](http://github.com/yolk/valvat/compare/v0.5.0...master)
4
+
5
+ ### 0.5.0 / 2019-06-13
6
+ [full changelog](http://github.com/yolk/valvat/compare/v0.4.3...v0.5.0)
7
+
8
+ * Added exclusive support for 1Rails 5.1 and upwards
9
+ * Renamed record_* methods to memento_record_after_*
10
+ * Fixed generators for Rails 4
4
11
 
5
12
  ### 0.4.3 / 2014-04-07
6
13
 
@@ -45,4 +52,4 @@
45
52
 
46
53
  [full changelog](http://github.com/yolk/valvat/compare/v0.3.4...v0.3.5)
47
54
 
48
- * Compatiblity with Rails 3.2
55
+ * Compatiblity with Rails 3.2
@@ -1,10 +1,14 @@
1
- class MementoMigrationGenerator < Rails::Generator::Base
2
- def manifest
3
- record do |m|
4
- m.migration_template("migration.rb", 'db/migrate',
5
- :assigns => { },
6
- :migration_file_name => "memento_migration"
7
- )
8
- end
1
+ require 'rails/generators'
2
+ require 'rails/generators/active_record'
3
+
4
+ class MementoMigrationGenerator < Rails::Generators::Base
5
+ include ::Rails::Generators::Migration
6
+ include ActiveRecord::Generators::Migration
7
+
8
+ source_root File.expand_path '../templates', __FILE__
9
+
10
+ def add_memento_migration
11
+ migration_template "migration.rb", 'db/migrate/memento_migration.rb'
9
12
  end
10
- end
13
+
14
+ end
@@ -1,9 +1,9 @@
1
1
  class MementoMigration < ActiveRecord::Migration
2
2
 
3
- def self.up
3
+ def change
4
4
  create_table :memento_sessions do |t|
5
5
  t.references :user
6
- t.timestamps
6
+ t.timestamps null: false
7
7
  end
8
8
 
9
9
  create_table :memento_states do |t|
@@ -11,13 +11,8 @@ class MementoMigration < ActiveRecord::Migration
11
11
  t.binary :record_data, :limit => 16777215
12
12
  t.references :record, :polymorphic => true
13
13
  t.references :session
14
- t.timestamps
14
+ t.timestamps null: false
15
15
  end
16
16
  end
17
17
 
18
- def self.down
19
- drop_table :memento_states
20
- drop_table :memento_sessions
21
- end
22
-
23
- end
18
+ end
@@ -53,6 +53,10 @@ module Memento
53
53
  @serializer ||= YAML
54
54
  end
55
55
 
56
+ def ignore?
57
+ !!Thread.current[:memento_ignore]
58
+ end
59
+
56
60
  private
57
61
 
58
62
  def session
@@ -63,10 +67,6 @@ module Memento
63
67
  Thread.current[:memento_session] = session
64
68
  end
65
69
 
66
- def ignore?
67
- !!Thread.current[:memento_ignore]
68
- end
69
-
70
70
  def save_session
71
71
  active? && (!session.changed? || session.save)
72
72
  end
@@ -76,9 +76,11 @@ end
76
76
  def Memento(user_or_id, &block)
77
77
  Memento.watch(user_or_id, &block)
78
78
  end
79
+
80
+ require 'memento/railtie'
79
81
  require 'memento/result'
80
82
  require 'memento/action'
81
83
  require 'memento/active_record_methods'
82
84
  require 'memento/action_controller_methods'
83
85
  require 'memento/state'
84
- require 'memento/session'
86
+ require 'memento/session'
@@ -52,4 +52,4 @@ module Memento
52
52
  record
53
53
  end
54
54
  end
55
- end
55
+ end
@@ -30,7 +30,7 @@ module Memento::ActiveRecordMethods
30
30
  end
31
31
 
32
32
  action_types.each do |action_type|
33
- send :"after_#{action_type}", :"record_#{action_type}"
33
+ send :"after_#{action_type}", :"memento_record_after_#{action_type}"
34
34
  end
35
35
 
36
36
  has_many :memento_states, :class_name => "Memento::State", :as => :record
@@ -54,7 +54,7 @@ module Memento::ActiveRecordMethods
54
54
  end
55
55
 
56
56
  def changes_for_memento
57
- filter_attributes_for_memento(changes)
57
+ filter_attributes_for_memento(saved_changes)
58
58
  end
59
59
 
60
60
  def filter_attributes_for_memento(hash)
@@ -70,13 +70,13 @@ module Memento::ActiveRecordMethods
70
70
  private :ignore_attributes_for_memento
71
71
 
72
72
  Memento::Action::Base.action_types.each do |action_type|
73
- define_method :"record_#{action_type}" do
73
+ define_method :"memento_record_after_#{action_type}" do
74
74
  Memento.add_state(action_type, self)
75
75
  end
76
- private :"record_#{action_type}"
76
+ private :"memento_record_after_#{action_type}"
77
77
  end
78
78
  end
79
79
 
80
80
  end
81
81
 
82
- ActiveRecord::Base.send(:include, Memento::ActiveRecordMethods) if defined?(ActiveRecord::Base)
82
+ ActiveRecord::Base.send(:include, Memento::ActiveRecordMethods) if defined?(ActiveRecord::Base)
@@ -0,0 +1,7 @@
1
+ module Memento
2
+ class Railtie < Rails::Railtie
3
+ generators do
4
+ require File.join File.dirname(__FILE__), '..', '..', 'generators', 'memento_migration', 'memento_migration_generator'
5
+ end
6
+ end
7
+ end if defined?(Rails)
@@ -12,13 +12,16 @@ module Memento
12
12
  validates_presence_of :action_type
13
13
  validates_inclusion_of :action_type, :in => Memento::Action::Base.action_types, :allow_blank => true
14
14
 
15
- before_create :set_record_data
15
+ # before_create :set_record_data
16
16
 
17
17
  def self.store(action_type, record)
18
18
  new do |state|
19
19
  state.action_type = action_type.to_s
20
20
  state.record = record
21
- state.save if state.fetch?
21
+ if state.fetch?
22
+ state.set_record_data
23
+ state.save
24
+ end
22
25
  end
23
26
  end
24
27
 
@@ -27,7 +30,7 @@ module Memento
27
30
  end
28
31
 
29
32
  def record_data
30
- @record_data ||= Memento.serializer.load(read_attribute(:record_data))
33
+ @record_data ||= read_attribute(:record_data) ? Memento.serializer.load(read_attribute(:record_data)) : {}
31
34
  end
32
35
 
33
36
  def record_data=(data)
@@ -39,14 +42,14 @@ module Memento
39
42
  action.fetch?
40
43
  end
41
44
 
42
- private
43
-
44
45
  def set_record_data
45
46
  self.record_data = action.fetch
46
47
  end
47
48
 
49
+ private
50
+
48
51
  def action
49
52
  "memento/action/#{action_type}".classify.constantize.new(self)
50
53
  end
51
54
  end
52
- end
55
+ end
@@ -1,3 +1,3 @@
1
1
  module Memento
2
- VERSION = "0.4.3"
3
- end
2
+ VERSION = "0.5.0"
3
+ end
@@ -17,8 +17,8 @@ Gem::Specification.new do |s|
17
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
18
  s.require_paths = ["lib"]
19
19
 
20
- s.add_dependency 'activerecord', '>= 3.2.5'
21
- s.add_dependency 'actionpack', '>= 3.2.5'
20
+ s.add_dependency 'activerecord', '>= 5.1'
21
+ s.add_dependency 'actionpack', '>= 5.1'
22
22
 
23
23
  s.add_development_dependency 'rspec', '>= 2.4.0'
24
24
  s.add_development_dependency 'sqlite3', '>= 1.3.5'
@@ -210,4 +210,4 @@ describe Memento::Action::Update do
210
210
 
211
211
  end
212
212
 
213
- end
213
+ end
@@ -8,7 +8,7 @@ describe Memento::ActiveRecordMethods do
8
8
  end
9
9
 
10
10
  it "should declare protected methods on Project" do
11
- Project.private_instance_methods.map(&:to_sym).should include(:record_destroy, :record_update, :record_create)
11
+ Project.private_instance_methods.map(&:to_sym).should include(:memento_record_after_destroy, :memento_record_after_update, :memento_record_after_create)
12
12
  end
13
13
 
14
14
  it "should set hook on create to call Memento" do
@@ -39,16 +39,6 @@ describe Memento::ActiveRecordMethods do
39
39
  Project.memento_options.should eql({:ignore=>[:ignore_this]})
40
40
  end
41
41
 
42
- it "should define changes_for_memento and ignore attributes given by options" do
43
- project = Project.create!(:name => "Project X")
44
- project.name = "A Project"
45
- project.updated_at = 5.minutes.ago
46
- project.notes = "new"
47
- project.ignore_this = 2
48
- project.changes_for_memento.should_not == project.changes
49
- project.changes_for_memento.should == {"name"=>["Project X", "A Project"], "notes"=>[nil, "new"]}
50
- end
51
-
52
42
  it "should define has_many association to memento_states" do
53
43
  project = Project.create!(:name => "Project X")
54
44
  project.memento_states.should be_empty
@@ -66,4 +56,4 @@ describe Memento::ActiveRecordMethods do
66
56
  shutdown_db
67
57
  end
68
58
 
69
- end
59
+ end
@@ -118,4 +118,4 @@ describe Memento::Session do
118
118
  shutdown_db
119
119
  end
120
120
 
121
- end
121
+ end
@@ -32,7 +32,8 @@ describe Memento::State do
32
32
 
33
33
  describe "valid State" do
34
34
  before do
35
- @state = @session.states.create!({:action_type => "destroy", :record => @project = Project.create(:name => "A")} )
35
+ @state = @session.states.store("destroy", @project = Project.create(:name => "A"))
36
+ @project.destroy
36
37
  end
37
38
 
38
39
  it "should give back Memento::Result on undo" do
@@ -51,4 +52,4 @@ describe Memento::State do
51
52
  shutdown_db
52
53
  end
53
54
 
54
- end
55
+ end
@@ -94,7 +94,7 @@ describe Memento do
94
94
  it "should give back false when no states created" do
95
95
  Memento(@user) do
96
96
  1 + 1
97
- end.should be_false
97
+ end.should eql(false)
98
98
  end
99
99
 
100
100
  it "should raise error in block and stop session" do
@@ -207,4 +207,4 @@ describe Memento do
207
207
  end
208
208
  end
209
209
 
210
- end
210
+ end
@@ -17,7 +17,13 @@ require 'memento'
17
17
 
18
18
  ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
19
19
  # catch AR schema statements
20
- $stdout = StringIO.new
20
+ # $stdout = StringIO.new
21
+
22
+ RSpec.configure do |config|
23
+ config.filter_run :focus
24
+ config.run_all_when_everything_filtered = true
25
+ config.expect_with(:rspec) { |c| c.syntax = :should }
26
+ end
21
27
 
22
28
  def setup_db
23
29
  ActiveRecord::Schema.define(:version => 1) do
@@ -27,18 +33,18 @@ def setup_db
27
33
  t.column :notes, :text
28
34
  t.references :customer
29
35
  t.integer :ignore_this
30
- t.timestamps
36
+ t.timestamps null: false
31
37
  end
32
38
 
33
39
  create_table :users do |t|
34
40
  t.column :email, :string
35
41
  t.column :name, :string
36
- t.timestamps
42
+ t.timestamps null: false
37
43
  end
38
44
 
39
45
  create_table :customers do |t|
40
46
  t.column :name, :string
41
- t.timestamps
47
+ t.timestamps null: false
42
48
  end
43
49
 
44
50
  create_table :timestampless_objects do |t|
@@ -47,7 +53,7 @@ def setup_db
47
53
 
48
54
  create_table :memento_sessions do |t|
49
55
  t.references :user
50
- t.timestamps
56
+ t.timestamps null: false
51
57
  end
52
58
 
53
59
  create_table :memento_states do |t|
@@ -55,7 +61,7 @@ def setup_db
55
61
  t.binary :record_data, :limit => 16777215
56
62
  t.references :record, :polymorphic => true
57
63
  t.references :session
58
- t.timestamps
64
+ t.timestamps null: false
59
65
  end
60
66
 
61
67
  end
@@ -79,11 +85,11 @@ class Customer < ActiveRecord::Base
79
85
  end unless defined?(Customer)
80
86
 
81
87
  class Project < ActiveRecord::Base
82
- belongs_to :customer
88
+ belongs_to :customer, optional: true
83
89
 
84
90
  memento_changes :ignore => :ignore_this
85
91
  end unless defined?(Project)
86
92
 
87
93
  class TimestamplessObject < ActiveRecord::Base
88
94
  memento_changes
89
- end unless defined?(TimestamplessObject)
95
+ end unless defined?(TimestamplessObject)
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memento
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yolk Sebastian Munz & Julia Soergel GbR
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-07 00:00:00.000000000 Z
11
+ date: 2019-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 3.2.5
19
+ version: '5.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 3.2.5
26
+ version: '5.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: actionpack
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 3.2.5
33
+ version: '5.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 3.2.5
40
+ version: '5.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: 2.4.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.4.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: sqlite3
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: 1.3.5
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: 1.3.5
69
69
  description: Undo for Rails/ActiveRecord - covers destroy, update and create
@@ -72,8 +72,7 @@ executables: []
72
72
  extensions: []
73
73
  extra_rdoc_files: []
74
74
  files:
75
- - .gitignore
76
- - .ruby-version
75
+ - ".gitignore"
77
76
  - CHANGES.md
78
77
  - Gemfile
79
78
  - LICENSE
@@ -90,6 +89,7 @@ files:
90
89
  - lib/memento/action/update.rb
91
90
  - lib/memento/action_controller_methods.rb
92
91
  - lib/memento/active_record_methods.rb
92
+ - lib/memento/railtie.rb
93
93
  - lib/memento/result.rb
94
94
  - lib/memento/session.rb
95
95
  - lib/memento/state.rb
@@ -114,17 +114,16 @@ require_paths:
114
114
  - lib
115
115
  required_ruby_version: !ruby/object:Gem::Requirement
116
116
  requirements:
117
- - - '>='
117
+ - - ">="
118
118
  - !ruby/object:Gem::Version
119
119
  version: '0'
120
120
  required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '>='
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  requirements: []
126
- rubyforge_project:
127
- rubygems_version: 2.0.3
126
+ rubygems_version: 3.0.3
128
127
  signing_key:
129
128
  specification_version: 4
130
129
  summary: Undo for Rails/ActiveRecord - covers destroy, update and create
@@ -1 +0,0 @@
1
- 2.0.0-p247