Skip to content
This repository was archived by the owner on Jun 2, 2020. 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ tmp
*.o
*.a
mkmf.log
.idea/
**/.DS_Store
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
language: ruby
rvm:
- 2.1.7
- 2.2.3
- 2.1.10
- 2.2.7
- 2.3.4
gemfile:
- gemfiles/Gemfile.Rails32
- gemfiles/Gemfile.Rails41
Expand Down
14 changes: 6 additions & 8 deletions cache-object.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ 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']

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'
Expand All @@ -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
6 changes: 6 additions & 0 deletions lib/cache/object/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/cache/object/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Cache
module Object
VERSION = '0.2.0'
VERSION = '1.0.0'
end
end
12 changes: 12 additions & 0 deletions spec/cache/object/active_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'cache/object'
require 'rspec/collection_matchers'
require 'rspec/its'

RSpec.configure do |config|

config.before(:each) do
Expand Down
3 changes: 2 additions & 1 deletion spec/support/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down