Skip to content
This repository was archived by the owner on Dec 2, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ cache:
bundler: true

rvm:
- 2.0.0
- 2.1
- 2.2
- 2.0
- 2.5

addons:
postgresql: "9.4"
Expand Down
7 changes: 3 additions & 4 deletions delta.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ Gem::Specification.new do |spec|

spec.add_runtime_dependency "request_store"

spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rake"
spec.add_development_dependency "awesome_print"
spec.add_development_dependency "rails", "~> 4.2"
spec.add_development_dependency "awesome_pry"
spec.add_development_dependency "rails", ">= 5.1", "< 5.2"
spec.add_development_dependency "rspec"
spec.add_development_dependency "rspec-rails"
spec.add_development_dependency "test_after_commit"
spec.add_development_dependency "pg"
#spec.add_development_dependency "rubocop"
end
20 changes: 10 additions & 10 deletions lib/delta/tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ def persist!(model, deltas = [])
deltas = [deltas] unless deltas.is_a?(Array)

model.cache_deltas(deltas)

if model.persisted?
Delta.config.adapters.each do |adapter|
"#{adapter}::Store"
.constantize
.new(model, model.deltas_cache)
.persist!
end

model.reset_deltas_cache!
return if model.deltas_cache.empty?
return unless model.persisted?

Delta.config.adapters.each do |adapter|
"#{adapter}::Store"
.constantize
.new(model, model.deltas_cache)
.persist!
end

model.reset_deltas_cache!
end

private
Expand Down
4 changes: 2 additions & 2 deletions lib/delta/tracker/association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def serialize(obj, action)
# loosing the main idea and without huge performance bottlenecks.
# And also think about tracking changes of polymorphic assocs.
def serialize_change(obj)
if (obj.changes.keys & @opts[:serialize]).any?
if (obj.saved_changes.keys & @opts[:serialize]).any?
serialize(obj, "C")
end
end
Expand All @@ -64,7 +64,7 @@ def track_association_change!
after_update do
t = #{@trackable_class}.delta_tracker
delta = t.trackable_fields['#{@name}'].serialize_change(self)
model = association_cache['#{assoc}'] || send('#{assoc}')
model = send('#{assoc}')

t.persist!(model, delta) if delta
end
Expand Down
2 changes: 1 addition & 1 deletion lib/delta/tracker/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(name, attr, opts = {})
def track!; end

def serialize(model, action, opts = {})
return unless changed = model.changes[@name]
return unless changed = model.changes_to_save[@name]

{
name: @name,
Expand Down
4 changes: 2 additions & 2 deletions lib/delta/tracker/belongs_to.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ def track!
end

def serialize(model, action, opts = {})
return unless model.changes[key] || (polymorphic? && model.changes[type])
return unless model.saved_changes[key] || (polymorphic? && model.saved_changes[type])

assoc = model.association_cache[@name] || model.send(@name)
assoc = model.send(@name)
key = @reflection.klass.primary_key
serialized = if assoc
{ key => assoc.send(key) }.tap do |hash|
Expand Down
10 changes: 5 additions & 5 deletions lib/delta/tracker/model_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ def self.included(base)
base.send :include, DeltaAssociationsMethods

base.class_eval do
before_update :cache_delta_fields!
before_save :cache_delta_fields!

if Delta.config.dont_use_after_commit_callbacks
# Might be useful in app's specs, for example
after_update :persist_delta_cache!
after_save :persist_delta_cache!

after_destroy :reset_deltas_cache!
after_create :reset_deltas_cache!
else
after_commit :persist_delta_cache!, on: :update
after_commit :reset_deltas_cache!, on: [:destroy, :create]
after_commit :persist_delta_cache!, on: [:create, :update]
after_commit :reset_deltas_cache!, on: :destroy
end
end
end
Expand All @@ -43,7 +43,7 @@ def persist_delta_cache!

module DeltaFieldsMethods
def cache_delta_fields!
return if changes.empty?
return unless has_changes_to_save?

ts = Time.now.to_i
deltas = []
Expand Down
2 changes: 1 addition & 1 deletion lib/delta/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Delta
VERSION = "0.0.1.alpha"
VERSION = "0.0.1"
end
2 changes: 1 addition & 1 deletion lib/generators/delta/templates/create_deltas.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CreateDeltas < ActiveRecord::Migration
class CreateDeltas < ActiveRecord::Migration[4.2]
def change
create_table :deltas, force: :cascade do |t|
# TODO: custom users key name
Expand Down
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@
CreateDeltas.new.change

RSpec.configure do |c|
require 'test_after_commit'
c.use_transactional_fixtures = true
end
1 change: 0 additions & 1 deletion spec/test_app/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class Application < Rails::Application
config.consider_all_requests_local = true
config.eager_load = false
config.encoding = "utf-8"
config.active_record.raise_in_transactional_callbacks = true

config.paths["app/controllers"] << "#{TEST_APP_PATH}/controllers"
config.paths["app/models"] << "#{TEST_APP_PATH}/models"
Expand Down
2 changes: 1 addition & 1 deletion spec/test_app/controllers/orders_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class OrdersController < ActionController::Base
def update_address
Order.last.update address: "new address"
render text: "ok"
render plain: "ok"
end

protected
Expand Down