From 5c7e3595918bdf70396c5aeea530b87f83e1435e Mon Sep 17 00:00:00 2001 From: Konstantin Gredeskoul Date: Thu, 10 Aug 2017 17:14:26 -0700 Subject: [PATCH 1/3] Adding `find_by` lookup to the cached list - bump version to 0.3.0 - update ruby versions on Travis CI - fix Rails deprecation warning - update authors in the gemspec. --- .gitignore | 2 ++ .travis.yml | 6 ++++-- cache-object.gemspec | 12 +++++------- lib/cache/object/active_record.rb | 6 ++++++ lib/cache/object/version.rb | 2 +- spec/cache/object/active_record_spec.rb | 12 ++++++++++++ spec/spec_helper.rb | 1 + spec/support/models.rb | 3 ++- 8 files changed, 33 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 299f9b8..10a178f 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,5 @@ tmp *.o *.a mkmf.log +.idea/ +**/.DS_Store diff --git a/.travis.yml b/.travis.yml index 49f42e4..fc5a9cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,9 @@ language: ruby rvm: - - 2.1.7 - - 2.2.3 + - 2.1.10 + - 2.2.7 + - 2.3.4 + - 2.4.1 gemfile: - gemfiles/Gemfile.Rails32 - gemfiles/Gemfile.Rails41 diff --git a/cache-object.gemspec b/cache-object.gemspec index b60ae7b..457dc3b 100644 --- a/cache-object.gemspec +++ b/cache-object.gemspec @@ -6,15 +6,14 @@ require 'cache/object/version' Gem::Specification.new do |spec| spec.name = 'cache-object' spec.version = Cache::Object::VERSION - spec.authors = ['Matt Camuto'] - spec.email = ['dev@wanelo.com'] - spec.summary = %q{Object R/W Caching} - spec.description = %q{Object R/W Caching on top of ActiveRecord} - spec.homepage = '' + spec.authors = ['Matt Camuto', 'Paul Henry', 'Konstantin Gredeskoul', 'Eric Saxby', 'Siyamed Sinir', 'Server Cimen'] + spec.email = ['dev@wanelo.com', 'kigster@gmail.com'] + spec.summary = %q{Cache ActiveRecord objects either by ID or by any other lookup field.} + spec.description = %q{Cache ActiveRecord objects either by ID or by any other lookup field.} + spec.homepage = 'https://github.com/wanelo/cache-object' spec.license = 'MIT' spec.files = `git ls-files -z`.split("\x0") - # spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ['lib'] @@ -31,5 +30,4 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'guard' spec.add_development_dependency 'guard-rspec' spec.add_development_dependency 'sqlite3' - end diff --git a/lib/cache/object/active_record.rb b/lib/cache/object/active_record.rb index b4d3fff..15130ea 100644 --- a/lib/cache/object/active_record.rb +++ b/lib/cache/object/active_record.rb @@ -94,6 +94,12 @@ def find(*args) end end + def find_by(*args) + Cache::Object.adapter.fetch(self, *args[0]) do + super(*args) + end + end + def find_by_id(id) Cache::Object.adapter.fetch(self, id) do where(self.primary_key => id).first diff --git a/lib/cache/object/version.rb b/lib/cache/object/version.rb index aa3671e..3414334 100644 --- a/lib/cache/object/version.rb +++ b/lib/cache/object/version.rb @@ -1,5 +1,5 @@ module Cache module Object - VERSION = '0.2.0' + VERSION = '0.3.0' end end diff --git a/spec/cache/object/active_record_spec.rb b/spec/cache/object/active_record_spec.rb index c36cbfe..9028d0f 100644 --- a/spec/cache/object/active_record_spec.rb +++ b/spec/cache/object/active_record_spec.rb @@ -18,6 +18,9 @@ def self.after_destroy(method) def self.find(id) end + def self.find_by(name: ) + end + def self.find_by_name_and_age(name, age) end end @@ -113,6 +116,15 @@ def fetch_mapping(klass, attributes) end end + describe '.find_by' do + describe 'caching interactions' do + it 'yields to super with cache' do + expect(super_clazz).to receive(:find_by).with(name: 12).once { double(first: true) } + clazz.find_by(name: 12) + end + end + end + describe '.fetch_all' do it 'should call through to multi_get' do multi_getter = double(fetch_all: true) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 03c7af4..f8614fa 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,7 @@ require 'cache/object' require 'rspec/collection_matchers' require 'rspec/its' + RSpec.configure do |config| config.before(:each) do diff --git a/spec/support/models.rb b/spec/support/models.rb index 7e8feea..57fed54 100644 --- a/spec/support/models.rb +++ b/spec/support/models.rb @@ -3,7 +3,8 @@ ActiveRecord::Migration.verbose = false ActiveRecord::Base.logger = Logger.new($STDOUT) -ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:') +ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') +ActiveRecord::Base.raise_in_transactional_callbacks = true if ActiveRecord::Base.respond_to?(:raise_in_transactional_callbacks=) module ActiveRecord class QueryCounter From e120cd8617b8d45eda8fc10a7a5ef20e5f8ac9fc Mon Sep 17 00:00:00 2001 From: Konstantin Gredeskoul Date: Thu, 10 Aug 2017 17:40:32 -0700 Subject: [PATCH 2/3] Removing 2.4.1 for now --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fc5a9cd..eb3c976 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ rvm: - 2.1.10 - 2.2.7 - 2.3.4 - - 2.4.1 gemfile: - gemfiles/Gemfile.Rails32 - gemfiles/Gemfile.Rails41 From 69eb4d6de39ff9af81c1255d7066ce97b5790415 Mon Sep 17 00:00:00 2001 From: Konstantin Gredeskoul Date: Mon, 23 Jul 2018 15:40:48 -0700 Subject: [PATCH 3/3] Version 1.0; removing rails5 compatibility --- cache-object.gemspec | 2 +- lib/cache/object/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cache-object.gemspec b/cache-object.gemspec index 457dc3b..306b944 100644 --- a/cache-object.gemspec +++ b/cache-object.gemspec @@ -17,7 +17,7 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ['lib'] - spec.add_dependency 'activerecord', ['>= 3.0', '< 4.3'] + spec.add_dependency 'activerecord', ['>= 3.0'] spec.add_dependency 'ruby-usdt' spec.add_development_dependency 'bundler', '~> 1.10' diff --git a/lib/cache/object/version.rb b/lib/cache/object/version.rb index 3414334..f9f4249 100644 --- a/lib/cache/object/version.rb +++ b/lib/cache/object/version.rb @@ -1,5 +1,5 @@ module Cache module Object - VERSION = '0.3.0' + VERSION = '1.0.0' end end