memento 0.4.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f19894c5e0f761d427f870ef788c38e3118f2a468c0607f0d7ea53bdcc4a30c6
4
+ data.tar.gz: cd3c89ab511c6583f512b2c090d4a38ff2552f96550fc38b04b119c646fbce36
5
+ SHA512:
6
+ metadata.gz: 9f190638d4cff502bf9f63a4ce191aaa6444010610a17fcb9acf4c186f6b3b2ca70de50cf81a02373dfddad4c9a82c488a56d0bcb8b95ff629eb10c9cd64b09f
7
+ data.tar.gz: d6d8a618bb8f3d9beae15d921ca77e67abc6b051b19f55fc8f56089274cd54837bd6b58d390580f37f6ff20eb490896d7463d037f9cac2e55d6f8c61177cc358
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,35 @@
1
1
  ### dev
2
2
 
3
- [full changelog](http://github.com/yolk/valvat/compare/v0.4.1...master)
3
+ [full changelog](http://github.com/yolk/valvat/compare/v0.5.2...master)
4
+
5
+ ### 0.5.2 / 2020-07-02
6
+ [full changelog](http://github.com/yolk/valvat/compare/v0.5.1...v0.5.2)
7
+
8
+ * Defer patching of rails base classes for zeitwerk loading
9
+
10
+ ### 0.5.1 / 2019-07-04
11
+ [full changelog](http://github.com/yolk/valvat/compare/v0.5.0...v0.5.1)
12
+
13
+ * Check attribute_without_formatting method for current value
14
+
15
+ ### 0.5.0 / 2019-06-13
16
+ [full changelog](http://github.com/yolk/valvat/compare/v0.4.3...v0.5.0)
17
+
18
+ * Added exclusive support for 1Rails 5.1 and upwards
19
+ * Renamed record_* methods to memento_record_after_*
20
+ * Fixed generators for Rails 4
21
+
22
+ ### 0.4.3 / 2014-04-07
23
+
24
+ [full changelog](http://github.com/yolk/valvat/compare/v0.4.2...v0.4.3)
25
+
26
+ * Full Rails 4 compatibility
27
+
28
+ ### 0.4.2 / 2013-07-19
29
+
30
+ [full changelog](http://github.com/yolk/valvat/compare/v0.4.1...v0.4.2)
31
+
32
+ * Replaced find_by_* calls for compatibility with ActiveRecord 4.0
4
33
 
5
34
  ### 0.4.1 / 2012-11-01
6
35
 
@@ -33,4 +62,4 @@
33
62
 
34
63
  [full changelog](http://github.com/yolk/valvat/compare/v0.3.4...v0.3.5)
35
64
 
36
- * Compatiblity with Rails 3.2
65
+ * Compatiblity with Rails 3.2
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in valvat.gemspec
4
- gemspec
4
+ gemspec
5
+
6
+ gem "rake"
@@ -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
@@ -20,8 +20,8 @@ module Memento
20
20
  end
21
21
 
22
22
  def start(user_or_id)
23
- user = user_or_id.is_a?(User) ? user_or_id : User.find_by_id(user_or_id)
24
- self.session = user ? Memento::Session.new({:user => user}, :without_protection => true) : nil
23
+ user = user_or_id.is_a?(User) ? user_or_id : User.where(:id => user_or_id).first
24
+ self.session = user ? Memento::Session.new(:user => user) : nil
25
25
  end
26
26
 
27
27
  def stop
@@ -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'
@@ -34,7 +34,9 @@ module Memento
34
34
  record_data.all? do |attribute, values|
35
35
  # ugly fix to compare times
36
36
  values = values.map{|v| v.is_a?(Time) ? v.to_s(:db) : v }
37
- current_value = record.send(:"#{attribute}")
37
+ current_value = record.respond_to?(:"#{attribute}_without_formatting") ?
38
+ record.send(:"#{attribute}_without_formatting") :
39
+ record.send(:"#{attribute}")
38
40
  current_value = current_value.utc.to_s(:db) if current_value.is_a?(Time)
39
41
  values.include?(current_value) || (current_value.is_a?(String) && values.include?(current_value.gsub(/\r\n/, "\n")))
40
42
  end || record_data.size.zero?
@@ -52,4 +54,4 @@ module Memento
52
54
  record
53
55
  end
54
56
  end
55
- end
57
+ end
@@ -15,4 +15,6 @@ module Memento
15
15
  end
16
16
  end
17
17
 
18
- ActionController::Base.send(:include, Memento::ActionControllerMethods) if defined?(ActionController::Base)
18
+ ActiveSupport.on_load(:action_controller) do
19
+ include Memento::ActionControllerMethods
20
+ 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,15 @@ 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
+ ActiveSupport.on_load(:active_record) do
83
+ include Memento::ActiveRecordMethods
84
+ end
@@ -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)
@@ -1,11 +1,11 @@
1
1
  module Memento
2
2
  class ResultArray < Array
3
3
  def errors
4
- self.find_all{ |result| result.failed? }
4
+ find_all{ |result| result.failed? }
5
5
  end
6
6
 
7
7
  def failed?
8
- self.any?{ |result| result.failed? }
8
+ any?{ |result| result.failed? }
9
9
  end
10
10
 
11
11
  def success?
@@ -2,10 +2,11 @@ module Memento
2
2
  class Session < ActiveRecord::Base
3
3
  self.table_name = "memento_sessions"
4
4
 
5
- has_many :states, :class_name => "Memento::State", :dependent => :delete_all, :order => "id DESC"
5
+ has_many :states, -> { order "id DESC" },
6
+ :class_name => "Memento::State", :dependent => :delete_all
6
7
  belongs_to :user
7
8
 
8
- attr_accessible nil
9
+ # attr_accessible nil
9
10
 
10
11
  validates_presence_of :user
11
12
 
@@ -5,20 +5,23 @@ module Memento
5
5
  belongs_to :session, :class_name => "Memento::Session"
6
6
  belongs_to :record, :polymorphic => true
7
7
 
8
- attr_accessible nil
8
+ # attr_accessible nil
9
9
 
10
10
  validates_presence_of :session
11
11
  validates_presence_of :record
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.1"
3
- end
2
+ VERSION = "0.5.2"
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'
@@ -21,7 +21,7 @@ describe Memento::Action::Create, "when object is created" do
21
21
  end
22
22
 
23
23
  it "should create object" do
24
- Project.find_by_id(@project.id).should_not be_nil
24
+ Project.where(:id => @project.id).first.should_not be_nil
25
25
  Project.count.should eql(1)
26
26
  end
27
27
 
@@ -22,7 +22,7 @@ describe Memento::Action::Destroy, "when object gets destroyed" do
22
22
  end
23
23
 
24
24
  it "should destroy object" do
25
- Project.find_by_id(@project.id).should be_nil
25
+ Project.where(:id => @project.id).first.should be_nil
26
26
  Project.count.should be_zero
27
27
  end
28
28
 
@@ -210,4 +210,4 @@ describe Memento::Action::Update do
210
210
 
211
211
  end
212
212
 
213
- end
213
+ end
@@ -10,9 +10,9 @@ describe Memento::ActionControllerMethods do
10
10
  setup_db
11
11
  setup_data
12
12
  @controller = FooController.new
13
- @controller.stub!(:current_user).and_return(@user)
13
+ @controller.stub(:current_user => @user)
14
14
  @headers = {}
15
- @controller.stub!(:response).and_return(mock("response", :headers => @headers))
15
+ @controller.stub_chain(:response, :headers => @headers)
16
16
  end
17
17
 
18
18
  after do
@@ -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
@@ -4,8 +4,8 @@ describe Memento::Result do
4
4
 
5
5
  describe "when initalized with valid object" do
6
6
  before do
7
- @object = mock("object", :errors => {})
8
- @state = mock("state1")
7
+ @object = double("object", :errors => {})
8
+ @state = double("state1")
9
9
  @result = Memento::Result.new(@object, @state)
10
10
  end
11
11
 
@@ -29,8 +29,8 @@ describe Memento::Result do
29
29
 
30
30
  describe "when initalized with object with errors" do
31
31
  before do
32
- @object = mock("object", :errors => {:memento_undo => "123"})
33
- @result = Memento::Result.new(@object, mock("state1"))
32
+ @object = double("object", :errors => {:memento_undo => "123"})
33
+ @result = Memento::Result.new(@object, double("state1"))
34
34
  end
35
35
 
36
36
  it "should have an object attribute" do
@@ -66,9 +66,9 @@ describe Memento::ResultArray do
66
66
 
67
67
  describe "when Memento::Result without errors added" do
68
68
  before do
69
- @object = mock("object", :errors => {:memento_undo => "123"})
70
- @results << Memento::Result.new(mock("object2", :errors => {}), mock("state1"))
71
- @results << (@with_error = Memento::Result.new(@object, mock("state2")))
69
+ @object = double("object", :errors => {:memento_undo => "123"})
70
+ @results << Memento::Result.new(double("object2", :errors => {}), double("state1"))
71
+ @results << (@with_error = Memento::Result.new(@object, double("state2")))
72
72
  end
73
73
 
74
74
  it "should have two entrys" do
@@ -5,7 +5,7 @@ describe Memento::Session do
5
5
  before do
6
6
  setup_db
7
7
  setup_data
8
- @session = Memento::Session.create({:user => @user}, :without_protection => true)
8
+ @session = Memento::Session.create({:user => @user})
9
9
  end
10
10
 
11
11
  it "should belong to user" do
@@ -17,24 +17,16 @@ describe Memento::Session do
17
17
  end
18
18
 
19
19
  it "should have_many states" do
20
- @session.states.should eql([])
21
- @session.states.create!({:action_type => "destroy", :record => Project.create!}, :without_protection => true)
20
+ @session.states.should be_empty
21
+ @session.states.create!({:action_type => "destroy", :record => Project.create!})
22
22
  @session.states.count.should eql(1)
23
23
  end
24
24
 
25
- it "should disallow all mass assignment" do
26
- Memento::Session.accessible_attributes.deny?("id").should eql(true)
27
- Memento::Session.accessible_attributes.deny?("created_at").should eql(true)
28
- Memento::Session.accessible_attributes.deny?("updated_at").should eql(true)
29
- Memento::Session.accessible_attributes.deny?("user_id").should eql(true)
30
- Memento::Session.accessible_attributes.deny?("user").should eql(true)
31
- end
32
-
33
25
  context "undo" do
34
26
  before do
35
- @state1 = @session.states.create!({:action_type => "update", :record => @p1 = Project.create!}, :without_protection => true)
36
- @other = Memento::Session.create!({:user => @user}, :without_protection => true).states.create!({:action_type => "destroy", :record => Project.create!}, :without_protection => true)
37
- @state2 = @session.states.create!({:action_type => "update", :record => @p2 = Project.create!}, :without_protection => true)
27
+ @state1 = @session.states.create!({:action_type => "update", :record => @p1 = Project.create!})
28
+ @other = Memento::Session.create!({:user => @user}).states.create!({:action_type => "destroy", :record => Project.create!})
29
+ @state2 = @session.states.create!({:action_type => "update", :record => @p2 = Project.create!})
38
30
  end
39
31
 
40
32
  describe "and all states succeed" do
@@ -49,15 +41,15 @@ describe Memento::Session do
49
41
 
50
42
  it "should remove itself" do
51
43
  @session.undo
52
- Memento::Session.find_by_id(@session.id).should be_nil
44
+ Memento::Session.where(:id => @session.id).first.should be_nil
53
45
  end
54
46
  end
55
47
 
56
48
  describe "and all states fail" do
57
49
  before do
58
- @state1.update_attributes({:record_data => {:name => ["A", "B"]}}, :without_protection => true)
50
+ @state1.update_attributes({:record_data => {:name => ["A", "B"]}})
59
51
  @p1.update_attributes(:name => "C")
60
- @state2.update_attributes({:record_data => {:name => ["A", "B"]}}, :without_protection => true)
52
+ @state2.update_attributes({:record_data => {:name => ["A", "B"]}})
61
53
  @p2.update_attributes(:name => "C")
62
54
  end
63
55
 
@@ -78,7 +70,7 @@ describe Memento::Session do
78
70
 
79
71
  describe "and some states succeed, some fail" do
80
72
  before do
81
- @state1.update_attributes({:record_data => {:name => ["A", "B"]}}, :without_protection => true)
73
+ @state1.update_attributes({:record_data => {:name => ["A", "B"]}})
82
74
  @p1.update_attributes(:name => "C")
83
75
  end
84
76
 
@@ -109,9 +101,9 @@ describe Memento::Session do
109
101
 
110
102
  describe "with states" do
111
103
  before do
112
- @session.states.create!({:action_type => "destroy", :record => Project.create!}, :without_protection => true)
113
- Memento::Session.create!({:user => @user}, :without_protection => true).states.create!({:action_type => "destroy", :record => Project.create!}, :without_protection => true)
114
- @state2 = @session.states.create!({:action_type => "update", :record => Project.create!}, :without_protection => true)
104
+ @session.states.create!({:action_type => "destroy", :record => Project.create!})
105
+ Memento::Session.create!({:user => @user}).states.create!({:action_type => "destroy", :record => Project.create!})
106
+ @state2 = @session.states.create!({:action_type => "update", :record => Project.create!})
115
107
  end
116
108
 
117
109
  it "should destroy all states when destroyed" do
@@ -126,4 +118,4 @@ describe Memento::Session do
126
118
  shutdown_db
127
119
  end
128
120
 
129
- end
121
+ end
@@ -5,11 +5,11 @@ describe Memento::State do
5
5
  before do
6
6
  setup_db
7
7
  setup_data
8
- @session = Memento::Session.create({:user => @user}, :without_protection => true)
8
+ @session = Memento::Session.create({:user => @user})
9
9
  end
10
10
 
11
11
  it "should belong to session" do
12
- Memento::State.new({:session => @session}, :without_protection => true).session.should eql(@session)
12
+ Memento::State.new({:session => @session}).session.should eql(@session)
13
13
  end
14
14
 
15
15
  it "should require session" do
@@ -18,32 +18,22 @@ describe Memento::State do
18
18
 
19
19
  it "should require action_type to be one of Memento::State::RECORD_CAUSES" do
20
20
  Memento::State.create.errors[:action_type].should eql(["can't be blank"])
21
- Memento::State.create({:action_type => "move"}, :without_protection => true).errors[:action_type].should eql(["is not included in the list"])
21
+ Memento::State.create({:action_type => "move"}).errors[:action_type].should eql(["is not included in the list"])
22
22
  end
23
23
 
24
24
  it "should belong to polymorphic record" do
25
- Memento::State.new({:record => @user}, :without_protection => true).record.should eql(@user)
26
- Memento::State.new({:record => @session}, :without_protection => true).record.should eql(@session)
25
+ Memento::State.new({:record => @user}).record.should eql(@user)
26
+ Memento::State.new({:record => @session}).record.should eql(@session)
27
27
  end
28
28
 
29
29
  it "should require record" do
30
30
  Memento::State.create.errors[:record].should eql(["can't be blank"])
31
31
  end
32
32
 
33
- it "should disallow all mass assignment" do
34
- Memento::State.accessible_attributes.deny?("id").should eql(true)
35
- Memento::State.accessible_attributes.deny?("created_at").should eql(true)
36
- Memento::State.accessible_attributes.deny?("updated_at").should eql(true)
37
- Memento::State.accessible_attributes.deny?("session_id").should eql(true)
38
- Memento::State.accessible_attributes.deny?("session").should eql(true)
39
- Memento::State.accessible_attributes.deny?("record_id").should eql(true)
40
- Memento::State.accessible_attributes.deny?("record_type").should eql(true)
41
- Memento::State.accessible_attributes.deny?("record").should eql(true)
42
- end
43
-
44
33
  describe "valid State" do
45
34
  before do
46
- @state = @session.states.create!({:action_type => "destroy", :record => @project = Project.create(:name => "A")}, :without_protection => true )
35
+ @state = @session.states.store("destroy", @project = Project.create(:name => "A"))
36
+ @project.destroy
47
37
  end
48
38
 
49
39
  it "should give back Memento::Result on undo" do
@@ -62,4 +52,4 @@ describe Memento::State do
62
52
  shutdown_db
63
53
  end
64
54
 
65
- 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
@@ -1,10 +1,13 @@
1
1
  require 'active_support'
2
+ require 'active_support/time'
2
3
  require 'active_record'
3
4
  require 'action_controller'
4
5
  require 'rspec'
5
6
 
7
+ I18n.enforce_available_locales = false
8
+
6
9
  # Initialize time_zones from rails
7
- Time.zone_default = (Time.respond_to?(:find_zone!) && Time.find_zone!("Berlin")) || Time.__send__(:get_zone, 'Berlin') || raise("Err")
10
+ Time.zone = "Berlin"
8
11
  ActiveRecord::Base.time_zone_aware_attributes = true
9
12
  ActiveRecord::Base.default_timezone = :utc
10
13
 
@@ -14,7 +17,13 @@ require 'memento'
14
17
 
15
18
  ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
16
19
  # catch AR schema statements
17
- $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
18
27
 
19
28
  def setup_db
20
29
  ActiveRecord::Schema.define(:version => 1) do
@@ -24,18 +33,18 @@ def setup_db
24
33
  t.column :notes, :text
25
34
  t.references :customer
26
35
  t.integer :ignore_this
27
- t.timestamps
36
+ t.timestamps null: false
28
37
  end
29
38
 
30
39
  create_table :users do |t|
31
40
  t.column :email, :string
32
41
  t.column :name, :string
33
- t.timestamps
42
+ t.timestamps null: false
34
43
  end
35
44
 
36
45
  create_table :customers do |t|
37
46
  t.column :name, :string
38
- t.timestamps
47
+ t.timestamps null: false
39
48
  end
40
49
 
41
50
  create_table :timestampless_objects do |t|
@@ -44,7 +53,7 @@ def setup_db
44
53
 
45
54
  create_table :memento_sessions do |t|
46
55
  t.references :user
47
- t.timestamps
56
+ t.timestamps null: false
48
57
  end
49
58
 
50
59
  create_table :memento_states do |t|
@@ -52,7 +61,7 @@ def setup_db
52
61
  t.binary :record_data, :limit => 16777215
53
62
  t.references :record, :polymorphic => true
54
63
  t.references :session
55
- t.timestamps
64
+ t.timestamps null: false
56
65
  end
57
66
 
58
67
  end
@@ -76,11 +85,11 @@ class Customer < ActiveRecord::Base
76
85
  end unless defined?(Customer)
77
86
 
78
87
  class Project < ActiveRecord::Base
79
- belongs_to :customer
88
+ belongs_to :customer, optional: true
80
89
 
81
90
  memento_changes :ignore => :ignore_this
82
91
  end unless defined?(Project)
83
92
 
84
93
  class TimestamplessObject < ActiveRecord::Base
85
94
  memento_changes
86
- end unless defined?(TimestamplessObject)
95
+ end unless defined?(TimestamplessObject)
metadata CHANGED
@@ -1,78 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memento
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
5
- prerelease:
4
+ version: 0.5.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Yolk Sebastian Munz & Julia Soergel GbR
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-11-01 00:00:00.000000000 Z
11
+ date: 2020-07-02 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: 3.2.5
19
+ version: '5.1'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
- version: 3.2.5
26
+ version: '5.1'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: actionpack
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
- version: 3.2.5
33
+ version: '5.1'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
- version: 3.2.5
40
+ version: '5.1'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: 2.4.0
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: 2.4.0
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: sqlite3
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: 1.3.5
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
68
  version: 1.3.5
78
69
  description: Undo for Rails/ActiveRecord - covers destroy, update and create
@@ -81,9 +72,7 @@ executables: []
81
72
  extensions: []
82
73
  extra_rdoc_files: []
83
74
  files:
84
- - .gitignore
85
- - .rbenv-gemsets
86
- - .rbenv-version
75
+ - ".gitignore"
87
76
  - CHANGES.md
88
77
  - Gemfile
89
78
  - LICENSE
@@ -100,6 +89,7 @@ files:
100
89
  - lib/memento/action/update.rb
101
90
  - lib/memento/action_controller_methods.rb
102
91
  - lib/memento/active_record_methods.rb
92
+ - lib/memento/railtie.rb
103
93
  - lib/memento/result.rb
104
94
  - lib/memento/session.rb
105
95
  - lib/memento/state.rb
@@ -117,27 +107,25 @@ files:
117
107
  - spec/spec_helper.rb
118
108
  homepage: http://github.com/yolk/memento
119
109
  licenses: []
120
- post_install_message:
110
+ metadata: {}
111
+ post_install_message:
121
112
  rdoc_options: []
122
113
  require_paths:
123
114
  - lib
124
115
  required_ruby_version: !ruby/object:Gem::Requirement
125
- none: false
126
116
  requirements:
127
- - - ! '>='
117
+ - - ">="
128
118
  - !ruby/object:Gem::Version
129
119
  version: '0'
130
120
  required_rubygems_version: !ruby/object:Gem::Requirement
131
- none: false
132
121
  requirements:
133
- - - ! '>='
122
+ - - ">="
134
123
  - !ruby/object:Gem::Version
135
124
  version: '0'
136
125
  requirements: []
137
- rubyforge_project:
138
- rubygems_version: 1.8.23
139
- signing_key:
140
- specification_version: 3
126
+ rubygems_version: 3.0.3
127
+ signing_key:
128
+ specification_version: 4
141
129
  summary: Undo for Rails/ActiveRecord - covers destroy, update and create
142
130
  test_files:
143
131
  - spec/memento/action/create_spec.rb
@@ -1 +0,0 @@
1
- plugin
@@ -1 +0,0 @@
1
- 1.9.3-p286