From 9e012b512adc5191c4aa3b09f71d45e3c3374db2 Mon Sep 17 00:00:00 2001 From: Pavel Date: Thu, 11 May 2017 15:34:51 +0300 Subject: [PATCH 1/4] table_exists? -> data_source_exists? --- lib/delta/tracking.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/delta/tracking.rb b/lib/delta/tracking.rb index 5971be0..7dd49bb 100644 --- a/lib/delta/tracking.rb +++ b/lib/delta/tracking.rb @@ -50,7 +50,7 @@ def track_deltas_on(field, field_opts = {}) private def init_delta_tracker_if_needed(opts) - unless connection.table_exists?(table_name) + unless connection.data_source_exists?(table_name) # TODO proper logging / errors Rails.logger.warn("[Delta] `#{table_name}` doesn't exist: skipping initialization.") return nil From feb8b4e40c8e136756220708bc3a59ba721e424b Mon Sep 17 00:00:00 2001 From: hats Date: Thu, 11 May 2017 18:28:25 +0300 Subject: [PATCH 2/4] association_cache -> association_instance_get --- lib/delta/tracker/association.rb | 2 +- lib/delta/tracker/belongs_to.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/delta/tracker/association.rb b/lib/delta/tracker/association.rb index 2895ae1..17a9e34 100644 --- a/lib/delta/tracker/association.rb +++ b/lib/delta/tracker/association.rb @@ -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 = association_instance_get('#{assoc}') || send('#{assoc}') t.persist!(model, delta) if delta end diff --git a/lib/delta/tracker/belongs_to.rb b/lib/delta/tracker/belongs_to.rb index 1fd30e2..fccc8d7 100644 --- a/lib/delta/tracker/belongs_to.rb +++ b/lib/delta/tracker/belongs_to.rb @@ -7,7 +7,7 @@ def track! def serialize(model, action, opts = {}) return unless model.changes[key] || (polymorphic? && model.changes[type]) - assoc = model.association_cache[@name] || model.send(@name) + assoc = model.association_instance_get(@name) || model.send(@name) key = @reflection.klass.primary_key serialized = if assoc { key => assoc.send(key) }.tap do |hash| From 2f5539c803812a1c6ff99d8f810656ed4da03131 Mon Sep 17 00:00:00 2001 From: hats Date: Thu, 11 May 2017 18:37:23 +0300 Subject: [PATCH 3/4] fix association_instance_get --- lib/delta/tracker/association.rb | 2 +- lib/delta/tracker/belongs_to.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/delta/tracker/association.rb b/lib/delta/tracker/association.rb index 17a9e34..1ffa112 100644 --- a/lib/delta/tracker/association.rb +++ b/lib/delta/tracker/association.rb @@ -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_instance_get('#{assoc}') || send('#{assoc}') + model = send(:association_instance_get, '#{assoc}') || send('#{assoc}') t.persist!(model, delta) if delta end diff --git a/lib/delta/tracker/belongs_to.rb b/lib/delta/tracker/belongs_to.rb index fccc8d7..e40a828 100644 --- a/lib/delta/tracker/belongs_to.rb +++ b/lib/delta/tracker/belongs_to.rb @@ -7,7 +7,7 @@ def track! def serialize(model, action, opts = {}) return unless model.changes[key] || (polymorphic? && model.changes[type]) - assoc = model.association_instance_get(@name) || model.send(@name) + assoc = model.send(:association_instance_get, @name) || model.send(@name) key = @reflection.klass.primary_key serialized = if assoc { key => assoc.send(key) }.tap do |hash| From 6a35bc600c603bb077dd41840ac682b2f00df5f0 Mon Sep 17 00:00:00 2001 From: hats Date: Wed, 24 May 2017 15:39:35 +0300 Subject: [PATCH 4/4] Add Polymorphic Profile association --- bin/console | 6 +- delta.gemspec | 33 +++++----- lib/delta.rb | 12 ++-- lib/delta/adapters/active_record/model.rb | 8 +-- lib/delta/adapters/active_record/store.rb | 2 +- lib/delta/config.rb | 10 +-- lib/delta/controller.rb | 8 +-- lib/delta/tracker/association.rb | 4 +- lib/delta/tracker/attribute.rb | 2 +- lib/delta/tracker/has_many.rb | 2 +- lib/delta/tracker/model_ext.rb | 8 +-- lib/delta/version.rb | 2 +- .../delta/create_table_generator.rb | 4 +- .../delta/templates/create_deltas.rb | 5 +- spec/delta_spec.rb | 20 +++--- spec/integration_spec.rb | 64 +++++++++---------- spec/requests/order_spec.rb | 12 +++- spec/spec_helper.rb | 1 - spec/test_app/application.rb | 21 +++--- spec/test_app/config/database.yml | 3 +- .../test_app/controllers/orders_controller.rb | 6 +- spec/test_app/models/another_order.rb | 2 +- 22 files changed, 121 insertions(+), 114 deletions(-) diff --git a/bin/console b/bin/console index f501600..726e650 100755 --- a/bin/console +++ b/bin/console @@ -1,7 +1,7 @@ #!/usr/bin/env ruby -require "bundler/setup" -require "delta" +require 'bundler/setup' +require 'delta' # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. @@ -10,5 +10,5 @@ require "delta" # require "pry" # Pry.start -require "irb" +require 'irb' IRB.start diff --git a/delta.gemspec b/delta.gemspec index 70e26f4..1aaccf1 100644 --- a/delta.gemspec +++ b/delta.gemspec @@ -4,37 +4,36 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'delta/version' Gem::Specification.new do |spec| - spec.name = "delta" + spec.name = 'delta' spec.version = Delta::VERSION - spec.authors = ["Theodore Konukhov"] - spec.email = ["me@thdr.io"] + spec.authors = ['Theodore Konukhov'] + spec.email = ['me@thdr.io'] spec.summary = %q{Deltas for ActiveRecord models} spec.description = %q{Deltas for ActiveRecord models} - spec.homepage = "https://github.com/konukhov/delta" - spec.license = "MIT" + spec.homepage = 'https://github.com/konukhov/delta' + spec.license = 'MIT' # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or # delete this section to allow pushing this gem to any host. if spec.respond_to?(:metadata) - spec.metadata['allowed_push_host'] = "https://rubygems.org" + spec.metadata['allowed_push_host'] = 'https://rubygems.org' else - raise "RubyGems 2.0 or newer is required to protect against public gem pushes." + raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.' end spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } - spec.bindir = "exe" + spec.bindir = 'exe' spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } - spec.require_paths = ["lib"] + spec.require_paths = ['lib'] - spec.add_runtime_dependency "request_store" + spec.add_runtime_dependency 'request_store' - spec.add_development_dependency "rake", "~> 10.0" - spec.add_development_dependency "awesome_print" - spec.add_development_dependency "rails", "~> 4.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 'rake', '~> 10.0' + spec.add_development_dependency 'awesome_print' + spec.add_development_dependency 'rails', '~> 5.0.2' + spec.add_development_dependency 'rspec' + spec.add_development_dependency 'rspec-rails' + spec.add_development_dependency 'pg' #spec.add_development_dependency "rubocop" end diff --git a/lib/delta.rb b/lib/delta.rb index eb2f4a4..3490ac4 100644 --- a/lib/delta.rb +++ b/lib/delta.rb @@ -42,22 +42,22 @@ def configure yield(config) end - def current_user - current_user_proc && current_user_proc.call + def current_profile + current_profile_proc && current_profile_proc.call end def store RequestStore end - def set_current_user_proc(proc) - store[:current_user_proc] = proc + def set_current_profile_proc(proc) + store[:current_profile_proc] = proc end private - def current_user_proc - store[:current_user_proc] + def current_profile_proc + store[:current_profile_proc] end end diff --git a/lib/delta/adapters/active_record/model.rb b/lib/delta/adapters/active_record/model.rb index f9ba833..70d0897 100644 --- a/lib/delta/adapters/active_record/model.rb +++ b/lib/delta/adapters/active_record/model.rb @@ -3,8 +3,8 @@ module Adapter module ActiveRecord module Ext def self.included(base) - klass_name = "Delta::Adapter::ActiveRecord::Model" - _scope = -> { order('created_at').includes(:user) } + klass_name = 'Delta::Adapter::ActiveRecord::Model' + _scope = -> { order('created_at').includes(:profile) } base.has_many :deltas, _scope, class_name: klass_name, @@ -13,12 +13,12 @@ def self.included(base) end class Model < ::ActiveRecord::Base - self.table_name = "deltas" + self.table_name = 'deltas' scope :newest, -> { reorder('created_at desc') } belongs_to :model, polymorphic: true - belongs_to :user + belongs_to :profile, polymorphic: true def readonly? persisted? diff --git a/lib/delta/adapters/active_record/store.rb b/lib/delta/adapters/active_record/store.rb index ea2ef1b..6212b10 100644 --- a/lib/delta/adapters/active_record/store.rb +++ b/lib/delta/adapters/active_record/store.rb @@ -14,7 +14,7 @@ def persist! def attrs @attrs ||= { object: @changes, - user: Delta.current_user + profile: Delta.current_profile } end end diff --git a/lib/delta/config.rb b/lib/delta/config.rb index c4202cc..135b5ce 100644 --- a/lib/delta/config.rb +++ b/lib/delta/config.rb @@ -5,15 +5,15 @@ module Delta class Config attr_reader :adapters - attr_accessor :controller_user_method, - :user_model, + attr_accessor :controller_profile_method, + :profile_model, :dont_use_after_commit_callbacks def initialize - @adapters = Adapters.new(["active_record"]) - @user_model = :user + @adapters = Adapters.new(%w[active_record]) + @profile_model = :user @dont_use_after_commit_callbacks = false - @controller_user_method = :current_user + @controller_profile_method = :current_user end def adapters=(adapter_names) diff --git a/lib/delta/controller.rb b/lib/delta/controller.rb index a7de8e4..faf32ed 100644 --- a/lib/delta/controller.rb +++ b/lib/delta/controller.rb @@ -3,12 +3,12 @@ module Controller def self.included(base) base.class_eval do before_action do - Delta.set_current_user_proc ->{ + Delta.set_current_profile_proc ->{ begin - self.send Delta.config.controller_user_method + self.send(Delta.config.controller_profile_method) rescue => e - Rails.logger.info "[Delta] Unable to get current " + - "user (#{e.class}: #{e.message})" + Rails.logger.info '[Delta] Unable to get current ' + + "profile (#{e.class}: #{e.message})" nil end } diff --git a/lib/delta/tracker/association.rb b/lib/delta/tracker/association.rb index 1ffa112..b42825e 100644 --- a/lib/delta/tracker/association.rb +++ b/lib/delta/tracker/association.rb @@ -43,7 +43,7 @@ def serialize(obj, action) # And also think about tracking changes of polymorphic assocs. def serialize_change(obj) if (obj.changes.keys & @opts[:serialize]).any? - serialize(obj, "C") + serialize(obj, 'C') end end @@ -82,7 +82,7 @@ def build_opts(opts) [] end - o[:only] = opts[:only] || ["add", "remove"] + o[:only] = opts[:only] || %w(add remove) o[:notify] = opts[:notify] || false end end diff --git a/lib/delta/tracker/attribute.rb b/lib/delta/tracker/attribute.rb index bfc4208..947be6a 100644 --- a/lib/delta/tracker/attribute.rb +++ b/lib/delta/tracker/attribute.rb @@ -12,7 +12,7 @@ def serialize(model, action, opts = {}) { name: @name, - action: "C", + action: 'C', timestamp: opts[:timestamp] || Time.now.to_i, object: changed.last } diff --git a/lib/delta/tracker/has_many.rb b/lib/delta/tracker/has_many.rb index 0fc5a10..31205c3 100644 --- a/lib/delta/tracker/has_many.rb +++ b/lib/delta/tracker/has_many.rb @@ -2,7 +2,7 @@ module Delta class Tracker class HasMany < Association def track! - actions = ["add", "remove"] + actions = %w(add remove) if @opts[:only].is_a?(Array) actions = @opts[:only].map(&:to_s) & actions diff --git a/lib/delta/tracker/model_ext.rb b/lib/delta/tracker/model_ext.rb index c17cc15..a257ba4 100644 --- a/lib/delta/tracker/model_ext.rb +++ b/lib/delta/tracker/model_ext.rb @@ -53,7 +53,7 @@ def cache_delta_fields! .merge(delta_tracker.attributes) fields.each do |name, field| - if serialized = field.serialize(self, "C", timestamp: ts) + if serialized = field.serialize(self, 'C', timestamp: ts) deltas << serialized end end @@ -66,15 +66,15 @@ def cache_delta_fields! module DeltaAssociationsMethods def delta_association_add(assoc_name, obj) - delta_association_invoke_action(assoc_name, obj, "A") + delta_association_invoke_action(assoc_name, obj, 'A') end def delta_association_remove(assoc_name, obj) - delta_association_invoke_action(assoc_name, obj, "R") + delta_association_invoke_action(assoc_name, obj, 'R') end def delta_association_change(assoc_name, obj) - delta_association_invoke_action(assoc_name, obj, "C") + delta_association_invoke_action(assoc_name, obj, 'C') end private diff --git a/lib/delta/version.rb b/lib/delta/version.rb index 180c086..25c0d09 100644 --- a/lib/delta/version.rb +++ b/lib/delta/version.rb @@ -1,3 +1,3 @@ module Delta - VERSION = "0.0.1.alpha" + VERSION = '0.0.1.alpha' end diff --git a/lib/generators/delta/create_table_generator.rb b/lib/generators/delta/create_table_generator.rb index c831d82..59747f6 100644 --- a/lib/generators/delta/create_table_generator.rb +++ b/lib/generators/delta/create_table_generator.rb @@ -6,14 +6,14 @@ module Generators class CreateTableGenerator < Rails::Generators::Base include Rails::Generators::Migration - source_root File.expand_path("../templates", __FILE__) + source_root File.expand_path('../templates', __FILE__) def self.next_migration_number(dirname) ::ActiveRecord::Generators::Base.next_migration_number(dirname) end def copy_migration - migration_template "create_deltas.rb", "db/migrate/create_deltas.rb" + migration_template 'create_deltas.rb', 'db/migrate/create_deltas.rb' end end end diff --git a/lib/generators/delta/templates/create_deltas.rb b/lib/generators/delta/templates/create_deltas.rb index 4ed4088..15ebdc3 100644 --- a/lib/generators/delta/templates/create_deltas.rb +++ b/lib/generators/delta/templates/create_deltas.rb @@ -2,11 +2,14 @@ class CreateDeltas < ActiveRecord::Migration def change create_table :deltas, force: :cascade do |t| # TODO: custom users key name - t.references :user, index: true + t.integer :profile_id + t.string :profile_type t.references :model, index: true, polymorphic: true t.json :object, null: false # TODO -> text if JSON is not supported t.timestamp :created_at end + + add_index :deltas, %i[profile_id profile_type] end end diff --git a/spec/delta_spec.rb b/spec/delta_spec.rb index 4e5dafb..11c7479 100644 --- a/spec/delta_spec.rb +++ b/spec/delta_spec.rb @@ -1,36 +1,36 @@ require 'spec_helper' describe Delta do - it "has config" do + it 'has config' do expect(Delta.config).to be_instance_of(Delta::Config) end - it "is configurable" do + it 'is configurable' do Delta.configure do |c| - c.controller_user_method = :current_admin + c.controller_profile_method = :current_admin end - expect(Delta.config.controller_user_method) + expect(Delta.config.controller_profile_method) .to eq(:current_admin) Delta.class_eval { @@config = Delta::Config.new } end - it "current_user is thread-safe" do + it 'current_user is thread-safe' do t1 = Thread.new do - Delta.set_current_user_proc ->{ :current_user_1 } + Delta.set_current_profile_proc ->{ :current_user_1 } sleep 0.2 - expect(Delta.current_user).to eq :current_user_1 + expect(Delta.current_profile).to eq :current_user_1 end t2 = Thread.new do sleep 0.1 - Delta.set_current_user_proc ->{ :current_user_2 } - expect(Delta.current_user).to eq :current_user_2 + Delta.set_current_profile_proc ->{ :current_user_2 } + expect(Delta.current_profile).to eq :current_user_2 end [t1, t2].map &:join - expect(Delta.current_user).to eq nil + expect(Delta.current_profile).to eq nil end end diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index c101772..14ded09 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -1,26 +1,26 @@ require 'spec_helper' require 'ap' -describe "Integration test" do - let(:user) { User.create(name: "user") } +describe 'Integration test' do + let(:user) { User.create(name: 'user') } let(:items) { [0, 1].map { |i| Item.create name: "Item #{i}" } } let(:last_delta_by_name) do ->(order, name){ order.deltas.last.object.select do |o| o['name'] == name - end.last["object"] + end.last['object'] } end - context "track deltas" do - let!(:order) { Order.create(address: "Address", items: items, user: user) } - let!(:empty_order) { Order.create address: "addr" } + context 'track deltas' do + let!(:order) { Order.create(address: 'Address', items: items, user: user) } + let!(:empty_order) { Order.create address: 'addr' } context 'attributes' do it 'tracks arrtibute change' do - addr = "new address" + addr = 'new address' expect { order.update(address: addr) } .to change(order.deltas, :count).by(1) @@ -31,12 +31,12 @@ context 'has_many associations' do context 'add' do it 'tracks has_many through association add' do - item = Item.create(name: "New item") + item = Item.create(name: 'New item') expect { order.items << item } .to change { order.reload.deltas.count }.by(1) - expect(last_delta_by_name[order, 'items']).to eq({ "id" => item.id }) + expect(last_delta_by_name[order, 'items']).to eq({ 'id' => item.id }) end it 'tracks has_many associations add via assoc_ids=' do @@ -82,7 +82,7 @@ }.to change(order.deltas, :count).by 1 expect(last_delta_by_name[order, 'image']) - .to eq({ "id" => order.image.id }) + .to eq({ 'id' => order.image.id }) end it 'tracks has_one association added by create_assoc' do @@ -91,7 +91,7 @@ }.to change(order.deltas, :count).by 1 expect(last_delta_by_name[order, 'image']) - .to eq({ "id" => order.image.id }) + .to eq({ 'id' => order.image.id }) end # it 'tracks has_one association added by build_assoc' do @@ -107,12 +107,12 @@ context 'belongs_to' do it 'tracks belongs_to associations' do - user = User.create(name: "New user") + user = User.create(name: 'New user') expect { order.update user: user } .to change(order.deltas, :count).by 1 - expect(last_delta_by_name[order, 'user']).to eq({ "id" => user.id }) + expect(last_delta_by_name[order, 'user']).to eq({ 'id' => user.id }) end end @@ -120,60 +120,60 @@ o = Order.create(address: 'addr', items: items, user: user) o.address = nil - o.user = User.create(name: "new user") + o.user = User.create(name: 'new user') expect { o.save }.not_to change(o.deltas, :count) - o.address = "new address" + o.address = 'new address' expect { o.save }.to change(o.deltas, :count).by(1) expect(o.deltas.last.object.map {|o| o['name'] } ) - .to contain_exactly("address", "user") + .to contain_exactly('address', 'user') end end - context "track deltas on" do - let!(:order) { AnotherOrder.create(address: "Address", items: items, user: user) } + context 'track deltas on' do + let!(:order) { AnotherOrder.create(address: 'Address', items: items, user: user) } # let!(:empty_order) { AnotherOrder.create address: "addr" } context 'has_many' do it 'tracks and serializes association' do - item = Item.create(name: "New item") + item = Item.create(name: 'New item') expect { order.items << item } .to change { order.reload.deltas.count }.by(1) expect(last_delta_by_name[order, 'items']) - .to eq({ "id" => item.id, "name" => item.name }) + .to eq({ 'id' => item.id, 'name' => item.name }) end end - context "has_one" do + context 'has_one' do it 'tracks has_one association' do expect { order.image = Image.create(url: 'whatever') }.to change(order.deltas, :count).by 1 expect(last_delta_by_name[order, 'image']) - .to eq({ "id" => order.image.id, "url" => order.image.url }) + .to eq({ 'id' => order.image.id, 'url' => order.image.url }) end end - context "belongs_to" do + context 'belongs_to' do it 'tracks belongs_to associations' do - user = User.create(name: "New user") + user = User.create(name: 'New user') expect { order.update user: user } .to change(order.deltas, :count).by 1 expect(last_delta_by_name[order, 'user']) - .to eq({ "id" => user.id, "name" => user.name }) + .to eq({ 'id' => user.id, 'name' => user.name }) end end context 'association changes' do it 'tracks change of has_many assoc' do - order.items << Item.create(name: "Item") + order.items << Item.create(name: 'Item') li = order.line_items.first @@ -181,20 +181,20 @@ li.update quantity: 2 }.to change(order.deltas, :count).by 1 - expect(last_delta_by_name[order, "line_items"]) - .to eq({"id" => li.id, "quantity" => 2}) + expect(last_delta_by_name[order, 'line_items']) + .to eq({ 'id' => li.id, 'quantity' => 2}) end it 'tracks change of has_one assoc' do - i = Image.create(url: "sample") + i = Image.create(url: 'sample') order.image = i expect { - i.update url: "new_url" + i.update url: 'new_url' }.to change(order.deltas, :count).by 1 - expect(last_delta_by_name[order, "image"]) - .to eq({"id" => i.id, "url" => "new_url"}) + expect(last_delta_by_name[order, 'image']) + .to eq({ 'id' => i.id, 'url' => 'new_url' }) end end diff --git a/spec/requests/order_spec.rb b/spec/requests/order_spec.rb index 9d75a5e..14e8ea1 100644 --- a/spec/requests/order_spec.rb +++ b/spec/requests/order_spec.rb @@ -1,13 +1,19 @@ require 'spec_helper' describe 'controller', type: :request do - let!(:order) { Order.create address: "Address" } + before do + Delta.config.controller_profile_method = :current_user + end + + let(:user) { User.create } + let!(:order) { Order.create address: 'Address', user: user } it 'tracks current_user in controller' do expect do - post "/orders/update_address" + post '/orders/update_address' end.to change(order.deltas, :count).by(1) - expect(order.deltas.last.user).to eq User.last + expect(order.deltas.last.profile).to eq User.last + pp order.deltas end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 04d4b6d..21612e4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -16,6 +16,5 @@ CreateDeltas.new.change RSpec.configure do |c| - require 'test_after_commit' c.use_transactional_fixtures = true end diff --git a/spec/test_app/application.rb b/spec/test_app/application.rb index 04add2b..152ca83 100644 --- a/spec/test_app/application.rb +++ b/spec/test_app/application.rb @@ -1,6 +1,6 @@ module TestApp - TEST_APP_PATH = File.expand_path("../", __FILE__) + TEST_APP_PATH = File.expand_path('../', __FILE__) class Application < Rails::Application config.action_controller.allow_forgery_protection = false @@ -12,19 +12,18 @@ class Application < Rails::Application config.cache_classes = true config.consider_all_requests_local = true config.eager_load = false - config.encoding = "utf-8" - config.active_record.raise_in_transactional_callbacks = true + config.encoding = 'utf-8' - config.paths["app/controllers"] << "#{TEST_APP_PATH}/controllers" - config.paths["app/models"] << "#{TEST_APP_PATH}/models" - config.paths["config/database"] = "#{TEST_APP_PATH}/config/database.yml" - config.paths["config/routes.rb"] << "#{TEST_APP_PATH}/config/routes.rb" - config.paths["db"] << "#{TEST_APP_PATH}/db" + config.paths['app/controllers'] << "#{TEST_APP_PATH}/controllers" + config.paths['app/models'] << "#{TEST_APP_PATH}/models" + config.paths['config/database'] = "#{TEST_APP_PATH}/config/database.yml" + config.paths['config/routes.rb'] << "#{TEST_APP_PATH}/config/routes.rb" + config.paths['db'] << "#{TEST_APP_PATH}/db" - config.secret_key_base = "SECRET_KEY_BASE" - config.secret_token = "HERE_S_MY_LOOOOOOOOONG_SECRET_TOKEN" + config.secret_key_base = 'SECRET_KEY_BASE' + config.secret_token = 'HERE_S_MY_LOOOOOOOOONG_SECRET_TOKEN' - null_logger = Logger.new("/dev/null") + null_logger = Logger.new('/dev/null') Rails.logger = null_logger ActiveRecord::Base.logger = null_logger end diff --git a/spec/test_app/config/database.yml b/spec/test_app/config/database.yml index 0b5ba93..9a38444 100644 --- a/spec/test_app/config/database.yml +++ b/spec/test_app/config/database.yml @@ -1,6 +1,7 @@ test: adapter: postgresql host: localhost - port: 5431 + port: 5432 user: iamakingbee + password: '' database: delta_test_db diff --git a/spec/test_app/controllers/orders_controller.rb b/spec/test_app/controllers/orders_controller.rb index 8313bab..c4817fd 100644 --- a/spec/test_app/controllers/orders_controller.rb +++ b/spec/test_app/controllers/orders_controller.rb @@ -1,13 +1,13 @@ class OrdersController < ActionController::Base def update_address - Order.last.update address: "new address" - render text: "ok" + Order.last.update address: 'new address' + head :no_content end protected def current_user - @current_user ||= User.create name: "Current user" + @current_user ||= User.create name: 'Current user' end helper_method :current_user end diff --git a/spec/test_app/models/another_order.rb b/spec/test_app/models/another_order.rb index 7c72f87..066d6ba 100644 --- a/spec/test_app/models/another_order.rb +++ b/spec/test_app/models/another_order.rb @@ -1,5 +1,5 @@ class AnotherOrder < ActiveRecord::Base - self.table_name = "orders" + self.table_name = 'orders' belongs_to :user # belongs_to :shop, polymorphic: true