findable 0.1.0 → 0.1.1

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: 3d9b4cc9d5f9ac6949eaa3db65f5dc97359a8450
4
- data.tar.gz: 3ca9a61d80ea9b8d74f5a4e2df78082f07083012
3
+ metadata.gz: 87900a069a5960243f4231d883d417f0b39c319c
4
+ data.tar.gz: 44fe61ca87bf212c297cacec0dd8c429dc371d65
5
5
  SHA512:
6
- metadata.gz: 68ab5f2cb1c8b3fc443ff1b4d1c8199a07634d3fb7ad08a7587247c0ee9836d711f596e2286566f82e59c9dccb2d815098e84e95adc665b0c878d3a721461a1c
7
- data.tar.gz: fdd8b84c3f07ded341d312cc6bd1117f2f64b61f5dc40865fa36877852c27b17562b6b2ff3bcb086344ec7e61317e01f058300c53d745b635e17658363793060
6
+ metadata.gz: c65b156840c789ea9338d6e574a67befcc28c6f8c3dfcdcff59aef446d3a37bb754b1018d2904b988e26783af48d6a2fa2676fdd570d04f7b385dcda3d079210
7
+ data.tar.gz: 9c851c3620d17317a35aeda778b80b23997ef0778e44e1de5750d5f403bf324e9eb12920b81726c3724ce54e4e5814241a24e423f3fa970fa424b885561841b0
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/findable.gemspec CHANGED
@@ -25,8 +25,10 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.add_development_dependency "bundler"
27
27
  spec.add_development_dependency "rake"
28
- spec.add_development_dependency "rspec-rails"
28
+ spec.add_development_dependency "rspec"
29
+ spec.add_development_dependency "activerecord"
29
30
  spec.add_development_dependency "pry"
30
31
  spec.add_development_dependency "coveralls"
32
+ spec.add_development_dependency "simplecov"
31
33
  end
32
34
 
data/lib/findable.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "active_support"
2
+ require "active_support/core_ext"
2
3
  require "active_model"
3
4
  require "redis/objects"
4
5
  require "oj"
data/lib/findable/base.rb CHANGED
@@ -114,7 +114,7 @@ module Findable
114
114
 
115
115
  def exists?(obj)
116
116
  if _id = id_from(obj)
117
- query.exists?(data_key, _id)
117
+ query.exists?(_id)
118
118
  else
119
119
  false
120
120
  end
@@ -1,4 +1,4 @@
1
1
  module Findable
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
4
4
 
@@ -0,0 +1,72 @@
1
+ require "spec_helper"
2
+
3
+ describe ActiveModel::Lint::Tests do
4
+ include_context "FindableModels"
5
+
6
+ context "#test_to_key" do
7
+ it "The model should respond to to_key" do
8
+ expect(findable_instance).to respond_to(:to_key)
9
+ end
10
+
11
+ it "to_key should return nil when `persisted?` returns false" do
12
+ allow(findable_instance).to receive(:persisted?).and_return(false)
13
+ expect(findable_instance.to_key).to be_nil
14
+ end
15
+ end
16
+
17
+ context "#test_to_param" do
18
+ it "The model should respond to to_param" do
19
+ expect(findable_instance).to respond_to(:to_param)
20
+ end
21
+
22
+ it "to_param should return nil when `persisted?` returns false" do
23
+ allow(findable_instance).to receive(:to_key).and_return([1])
24
+ allow(findable_instance).to receive(:persisted?).and_return(false)
25
+ expect(findable_instance.to_param).to be_nil
26
+ end
27
+ end
28
+
29
+ context "#test_to_partial_path" do
30
+ it "The model should respond to to_partial_path" do
31
+ expect(findable_instance).to respond_to(:to_partial_path)
32
+ end
33
+
34
+ it { expect(findable_instance.to_partial_path).to be_kind_of(String) }
35
+ end
36
+
37
+ context "#test_persisted?" do
38
+ it "The model should respond to persisted?" do
39
+ expect(findable_instance).to respond_to(:persisted?)
40
+ end
41
+
42
+ it "persisted?" do
43
+ bool = findable_instance.persisted?
44
+ expect(bool == true || bool == false).to be_truthy
45
+ end
46
+ end
47
+
48
+ context "#test_model_naming" do
49
+ it "The model class should respond to model_name" do
50
+ expect(findable_instance).to respond_to(:model_name)
51
+ end
52
+
53
+ it { expect(findable_model.model_name).to respond_to(:to_str) }
54
+ it { expect(findable_model.model_name.human).to respond_to(:to_str) }
55
+ it { expect(findable_model.model_name.singular).to respond_to(:to_str) }
56
+ it { expect(findable_model.model_name.plural).to respond_to(:to_str) }
57
+
58
+ it { expect(findable_instance).to respond_to(:model_name) }
59
+ it { expect(findable_instance.model_name).to eq(findable_model.model_name) }
60
+ end
61
+
62
+ context "#test_errors_aref" do
63
+ it "The model should respond to errors" do
64
+ expect(findable_instance).to respond_to(:errors)
65
+ end
66
+
67
+ it "errors#[] should return an Array" do
68
+ expect(findable_instance.errors[:hello]).to be_kind_of(Array)
69
+ end
70
+ end
71
+ end
72
+
@@ -0,0 +1,32 @@
1
+ require "spec_helper"
2
+
3
+ describe Findable::Associations::Utils do
4
+ let(:utils) { Findable::Associations::Utils }
5
+
6
+ describe "#model_for" do
7
+ include_context "FindableModels"
8
+ let(:model_name) { findable_model.model_name }
9
+
10
+ it { expect(utils.model_for(model_name.singular)).to eq(findable_model) }
11
+ it { expect(utils.model_for(model_name.plural, collection: true)).to eq(findable_model) }
12
+ it { expect(utils.model_for("invalid", class_name: model_name.name)).to eq(findable_model) }
13
+
14
+ it { expect { utils.model_for("invalid") }.to raise_error }
15
+ it { expect { utils.model_for("invalid", safe: true) }.not_to raise_error }
16
+ it { expect(utils.model_for("invalid", safe: true)).to be_nil }
17
+ end
18
+
19
+ describe "#parse_args" do
20
+ let(:parsed_args) { [:some_name, {class_name: "SomeClass"}] }
21
+ let(:args) { [parsed_args.first, **parsed_args.last] }
22
+
23
+ it { expect(utils.parse_args(args)).to eq(parsed_args) }
24
+
25
+ it {
26
+ expect {
27
+ utils.parse_args(args)
28
+ }.not_to change { args }
29
+ }
30
+ end
31
+ end
32
+
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ describe Findable::Associations do
4
+ include_context "AssociationModels"
5
+ let(:group) { Group.first }
6
+ let(:info) { Info.first }
7
+ let(:tag) { Tag.first }
8
+
9
+ describe "#has_many" do
10
+ it { expect(group.tags.map(&:id).sort).to eq(Tag.all.map(&:id).sort) }
11
+ end
12
+
13
+ describe "#has_one" do
14
+ it { expect(group.info.id).to eq(info.id) }
15
+ end
16
+
17
+ describe "#belongs_to" do
18
+ it { expect(tag.group.id).to eq(group.id) }
19
+ end
20
+ end
21
+
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,21 @@
1
- require "findable"
1
+ require "simplecov"
2
2
  require "coveralls"
3
3
  Coveralls.wear!
4
4
 
5
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
+ SimpleCov::Formatter::HTMLFormatter,
7
+ Coveralls::SimpleCov::Formatter
8
+ ]
9
+
10
+ SimpleCov.start do
11
+ add_filter "spec"
12
+ add_filter ".bundle"
13
+ add_filter "example"
14
+ end
15
+
16
+ require "pry"
17
+ require "findable"
18
+
5
19
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
6
20
 
7
21
  RSpec.configure do |config|
@@ -0,0 +1,29 @@
1
+ shared_context "FindableModels" do
2
+ before { class Tag < Findable::Base; end }
3
+ after { Object.send(:remove_const, "Tag") }
4
+
5
+ let(:findable_model) { Tag }
6
+ let(:findable_instance) { Tag.new }
7
+ end
8
+
9
+ shared_context "AssociationModels" do
10
+ before do
11
+ class Group < Findable::Base; end
12
+ class Tag < Findable::Base; end
13
+ class Info < Findable::Base; end
14
+ Group.has_many :tags
15
+ Group.has_one :info
16
+ Tag.belongs_to :group
17
+ Info.belongs_to :group
18
+
19
+ Group.query.import([{id: 1, name: "group1"}])
20
+ Tag.query.import([
21
+ {id: 1, name: "tag1", group_id: 1},
22
+ {id: 2, name: "tag2", group_id: 1},
23
+ ])
24
+ Info.query.import([{id: 1, group_id: 1}])
25
+ end
26
+
27
+ after { %w(Group Tag Info).each {|name| Object.send(:remove_const, name) } }
28
+ end
29
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: findable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - i2bskn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-05 00:00:00.000000000 Z
11
+ date: 2015-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -95,7 +95,21 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: rspec-rails
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: activerecord
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - ">="
@@ -136,6 +150,20 @@ dependencies:
136
150
  - - ">="
137
151
  - !ruby/object:Gem::Version
138
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: simplecov
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
139
167
  description: Redis wrapper with API like ActiveRecord.
140
168
  email:
141
169
  - i2bskn@gmail.com
@@ -145,6 +173,7 @@ extra_rdoc_files: []
145
173
  files:
146
174
  - ".coveralls.yml"
147
175
  - ".gitignore"
176
+ - ".rspec"
148
177
  - ".travis.yml"
149
178
  - Gemfile
150
179
  - LICENSE.txt
@@ -168,12 +197,16 @@ files:
168
197
  - lib/generators/findable/templates/findable.rb
169
198
  - lib/generators/findable/templates/seeds.rb
170
199
  - lib/tasks/findable.rake
200
+ - spec/active_model_lint_spec.rb
171
201
  - spec/findable/.keep
202
+ - spec/findable/associations/utils_spec.rb
203
+ - spec/findable/associations_spec.rb
172
204
  - spec/findable/base_spec.rb
173
205
  - spec/findable/configuration_spec.rb
174
206
  - spec/spec_helper.rb
175
207
  - spec/support/.keep
176
208
  - spec/support/initialize_redis.rb
209
+ - spec/support/shard_contexts.rb
177
210
  homepage: https://github.com/i2bskn/findable
178
211
  licenses:
179
212
  - MIT
@@ -199,9 +232,13 @@ signing_key:
199
232
  specification_version: 4
200
233
  summary: Redis wrapper with API like ActiveRecord.
201
234
  test_files:
235
+ - spec/active_model_lint_spec.rb
202
236
  - spec/findable/.keep
237
+ - spec/findable/associations/utils_spec.rb
238
+ - spec/findable/associations_spec.rb
203
239
  - spec/findable/base_spec.rb
204
240
  - spec/findable/configuration_spec.rb
205
241
  - spec/spec_helper.rb
206
242
  - spec/support/.keep
207
243
  - spec/support/initialize_redis.rb
244
+ - spec/support/shard_contexts.rb