ar_lookups 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b360d35220df4478720deeb64e3461e7b79e0cc3
4
- data.tar.gz: e5e20327d8b5edf5a85014d1b8fa20ccd59b755f
3
+ metadata.gz: 702c058bf42be5107f36fbbc821c47a61cbd9c09
4
+ data.tar.gz: 50352f03db716f8f5b26a5f5822f3aee08fdcd40
5
5
  SHA512:
6
- metadata.gz: c48ecd13b18102cafff26e2d4a10cd78ef9b5118987274d0b1b8c3f276cd7f87b9a1c81b463b3815cd92fd19f2d8471bfdfd7b4d5a453df588554a9a59700a07
7
- data.tar.gz: 27bb0090eb9baff947db3e6c3a2255037df170326312c42223000ce4eae8886860ca2015f3146c7fac1280bd53a92241e19c43420ddb8866cb3035e4de0d81e6
6
+ metadata.gz: d22820b18e1a0ce78a426b39483891ea8b89de882413d5230f8f42c0036c5177b361c0cd32ed3a6427d34fb8ea9feba43b101ddeb5df67c728cc1cc6f88e14d5
7
+ data.tar.gz: 3a574dd90237e9a8d292a52d9d42303993f8779d5ae0f8c06a1998679880f94e509cf1eab48df0fcd166cbd41afe6cc132da8a30ef097d7db53ea8755ac91cf2
@@ -2,7 +2,7 @@ require 'active_record'
2
2
 
3
3
  require 'ar_lookups/version'
4
4
  require 'ar_lookups/lookup_table_definition'
5
- require 'ar_lookups/base_ext'
5
+ require 'ar_lookups/activerecord_ext'
6
6
  require 'ar_lookups/railtie' if defined?(Rails)
7
7
 
8
8
  module ArLookups
@@ -1,5 +1,5 @@
1
1
  module ArLookups
2
- module BaseExt
2
+ module ActiveRecordExt
3
3
  def ar_lookups
4
4
  @ar_lookups ||= superclass.respond_to?(:ar_lookups) ? superclass.ar_lookups.dup : {}
5
5
  end
@@ -24,8 +24,9 @@ module ArLookups
24
24
  mod.class_eval <<-RUBY, __FILE__, __LINE__ + 1
25
25
  def #{column}
26
26
  keys = read_attribute(:#{column})
27
- return {} if keys.blank?
28
- Hash[self.class.ar_lookups[:#{column}].where('#{options[:key_column]} IN (?)', keys).pluck(:#{options[:key_column]}, :#{options[:name_column]})]
27
+ klass = self.class.ar_lookups[:#{column}]
28
+ return klass.none if keys.blank?
29
+ self.class.ar_lookups[:#{column}].where('#{options[:key_column]} IN (?)', keys)#.pluck(:#{options[:key_column]}, :#{options[:name_column]})]
29
30
  end
30
31
 
31
32
  def #{column}_ids
@@ -12,7 +12,7 @@ module ArLookups
12
12
 
13
13
  # Extend AR base
14
14
  ActiveRecord::Base.send :extend,
15
- ArLookups::BaseExt
15
+ ArLookups::ActiveRecordExt
16
16
  end
17
17
  end
18
18
  end
@@ -1,3 +1,3 @@
1
1
  module ArLookups
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar_lookups
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stan Bondi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-13 00:00:00.000000000 Z
11
+ date: 2014-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activerecord-nulldb-adapter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description:
70
84
  email:
71
85
  - stan@fixate.it
@@ -73,22 +87,16 @@ executables: []
73
87
  extensions: []
74
88
  extra_rdoc_files: []
75
89
  files:
76
- - ".gitignore"
77
- - ".rspec"
78
90
  - Gemfile
79
91
  - Guardfile
80
92
  - LICENSE.txt
81
93
  - README.md
82
94
  - Rakefile
83
- - ar_lookups.gemspec
84
95
  - lib/ar_lookups.rb
85
- - lib/ar_lookups/base_ext.rb
96
+ - lib/ar_lookups/activerecord_ext.rb
86
97
  - lib/ar_lookups/lookup_table_definition.rb
87
98
  - lib/ar_lookups/railtie.rb
88
99
  - lib/ar_lookups/version.rb
89
- - spec/base_ext_spec.rb
90
- - spec/lookup_table_definition_spec.rb
91
- - spec/spec_helper.rb
92
100
  homepage: https://github.com/fixate/ar_ar_lookups
93
101
  licenses:
94
102
  - MIT
@@ -113,7 +121,4 @@ rubygems_version: 2.2.0
113
121
  signing_key:
114
122
  specification_version: 4
115
123
  summary: Lookup tables using activerecord and array fields
116
- test_files:
117
- - spec/base_ext_spec.rb
118
- - spec/lookup_table_definition_spec.rb
119
- - spec/spec_helper.rb
124
+ test_files: []
data/.gitignore DELETED
@@ -1,17 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --format progress
@@ -1,25 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'ar_lookups/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "ar_lookups"
8
- spec.version = ArLookups::VERSION
9
- spec.authors = ["Stan Bondi"]
10
- spec.email = ["stan@fixate.it"]
11
- spec.summary = %q{Lookup tables using activerecord and array fields}
12
- spec.homepage = "https://github.com/fixate/ar_ar_lookups"
13
- spec.license = "MIT"
14
-
15
- spec.files = `git ls-files -z`.split("\x0")
16
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
- spec.require_paths = ["lib"]
19
-
20
- spec.add_dependency 'rails', '~> 4.0'
21
-
22
- spec.add_development_dependency "bundler", "~> 1.5"
23
- spec.add_development_dependency "rake"
24
- spec.add_development_dependency "rspec-rails"
25
- end
@@ -1,74 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class FooBar; end
4
-
5
- describe ArLookups::BaseExt do
6
- let(:lookup_relation) { mock_model('Dummy', pluck: []) }
7
- let(:lookup) do
8
- mock_model('Lookup', where: lookup_relation)
9
- end
10
-
11
- let(:client_class) do
12
- @class = Class.new
13
- @class.class_eval do
14
- def write_attribute(column, val)
15
- unless respond_to?(column)
16
- class_eval <<-RUBY, __FILE__, __LINE__+1
17
- attr_accessor :#{column}
18
- RUBY
19
- end
20
-
21
- instance_variable_set("@#{column}".to_sym, val)
22
- end
23
-
24
- def read_attribute(column)
25
- instance_variable_get("@#{column}".to_sym)
26
- end
27
- end
28
-
29
- @class.send(:extend, ArLookups::BaseExt)
30
- @class.lookup :foo, lookup
31
- @class
32
- end
33
-
34
- subject { client_class.new }
35
-
36
- it 'fetches values with keys' do
37
- expect(lookup).to receive(:where).with('key IN (?)', [1])
38
- expect(lookup_relation).to receive(:pluck).with(:key, :name)
39
-
40
- subject.foo = [1]
41
- subject.foo
42
- end
43
-
44
- it 'fetches values with different key name' do
45
- client_class.lookup :bar, lookup, key_column: :id, name_column: :place
46
- expect(lookup).to receive(:where).with('id IN (?)', [1])
47
- expect(lookup_relation).to receive(:pluck).with(:id, :place)
48
-
49
- subject.bar = [1]
50
- subject.bar
51
- end
52
-
53
- it 'returns ids from lookup' do
54
- subject.foo = [1,2]
55
- expect(subject.foo_ids).to eq([1,2])
56
- end
57
-
58
- it 'returns an empty hash if ar_lookups empty' do
59
- expect(subject.foo).to eq({})
60
- end
61
-
62
- it 'returns a hash' do
63
- subject.foo = [1,2]
64
- expect(subject.foo).to be_kind_of(Hash)
65
- end
66
-
67
- it 'implicitly gets the model name from the column' do
68
- client_class.class_eval do
69
- lookup :foo_bars
70
- end
71
-
72
- expect(client_class.ar_lookups[:foo_bars]).to be(FooBar)
73
- end
74
- end
@@ -1,22 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ArLookups::LookupTableDefinition do
4
- subject do
5
- class TableDefinition; include ArLookups::LookupTableDefinition; end.new
6
- end
7
-
8
- it 'creates an integer array column with default' do
9
- expect(subject).to receive(:integer).with(:foo, {array: true, default: []})
10
- subject.lookup :foo
11
- end
12
-
13
- it 'merges additional options in preserving array:true' do
14
- expect(subject).to receive(:integer).with(:foo, {test: 'foobar', array: true, default: []})
15
- subject.lookup :foo, test: 'foobar'
16
- end
17
-
18
- it 'uses default if given' do
19
- expect(subject).to receive(:integer).with(:foo, {default: [1, 2], array: true, default: []})
20
- subject.lookup :foo, default: [1, 2]
21
- end
22
- end
@@ -1,27 +0,0 @@
1
- # This file was generated by the `rspec --init` command. Conventionally, all
2
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # Require this file using `require "spec_helper"` to ensure that it is only
4
- # loaded once.
5
- #
6
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
-
8
- require 'rails/all'
9
- require 'rspec'
10
- require 'rspec/mocks'
11
- require 'rspec/rails/mocks'
12
- require 'rspec/autorun'
13
-
14
- require 'ar_lookups'
15
-
16
- RSpec.configure do |config|
17
- config.treat_symbols_as_metadata_keys_with_true_values = true
18
- config.run_all_when_everything_filtered = true
19
- config.filter_run :focus
20
-
21
- # Run specs in random order to surface order dependencies. If you find an
22
- # order dependency and want to debug it, you can fix the order by providing
23
- # the seed, which is printed after each run.
24
- # --seed 1234
25
- config.order = 'random'
26
- end
27
-