acts-as-taggable-array-on 0.4.2 → 0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a77a0ec0610eefe1f30f46cdceea0506283044dc
4
- data.tar.gz: d3a309690f4f0277752d68c270f937a6c67a66d1
2
+ SHA256:
3
+ metadata.gz: 6e9634fcc6fb7b4ddff2df2ae5e71bd237e89dcfbebdbec0cecc9d414d095821
4
+ data.tar.gz: 33745344b55b6a5ec70e530d530ccab286e606cfa925dc3cc06899b9f0bba54d
5
5
  SHA512:
6
- metadata.gz: dfef9bc472538240ea718500f4f3295c3bdf684ede2e4d35d81055406a8ab51040d7a8dd864ab30264d7bbed12c8055a6e3a3e36406ec54c522ee3287306a23a
7
- data.tar.gz: 5a7de21d8081ad1dfc2916cdb0e7f19c4c14219fb8f89ad619d069e2e7d636715f5b1d143dc9b677edb95a8ac2091e5e90d8809b19690e0be4fca7ad4722ebf9
6
+ metadata.gz: d4ef02fa959e7e24bfd78eb338de5b7f05d6a139357766db145c158f547a31af119d9e9a566180fdb3764ee98484f962e0619e00bf61cb0fb62a981137a84ff6
7
+ data.tar.gz: 75419a2e0d898ab7f6ce2a3a61e24298b8635e4a4bea5c3d87f95449b155bf260e42f53ff39470bccfd0d408e5ad195d09ac37885beff858f3419effa146e9a1
@@ -0,0 +1,13 @@
1
+ # top-most EditorConfig file
2
+ root = true
3
+
4
+ # Unix-style newlines with a newline ending every file
5
+ # Two spaces for indenting
6
+ [*]
7
+ end_of_line = lf
8
+ insert_final_newline = true
9
+ indent_style = space
10
+ indent_size = 2
11
+ charset = utf-8
12
+ trim_trailing_whitespace = true
13
+ max_line_length = 120
@@ -12,8 +12,7 @@ gemfile:
12
12
  - gemfiles/rails_4.gemfile
13
13
  - gemfiles/rails_5.gemfile
14
14
  before_script:
15
- - createuser -d acts-as-taggable-array-on -U postgres
16
- - createdb --username=acts-as-taggable-array-on acts-as-taggable-array-on_test
15
+ - bundle exec rake db:create
17
16
  script:
18
17
  - bundle
19
18
  - bundle exec rspec
data/README.md CHANGED
@@ -216,6 +216,9 @@ Using Postgres Arrays 0.030000 0.000000 0.030000 ( 0.033001)
216
216
  rake bench:write bench:find_by_id bench:find_by_tag 20.29s user 1.52s system 77% cpu 28.322 total
217
217
  ```
218
218
 
219
+ ## Development
220
+ To run testsuite you'll need to setup local PG database/user with `rake db:create`
221
+ After that just running `rspec` should work.
219
222
 
220
223
  ## Contributing
221
224
 
data/Rakefile CHANGED
@@ -1 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ namespace :db do
4
+ desc "Create database for tests"
5
+ task :create do
6
+ puts %x( createuser -d acts-as-taggable-array-on -U postgres )
7
+ puts %x( createdb --username=acts-as-taggable-array-on acts-as-taggable-array-on_test )
8
+ end
9
+ end
@@ -28,4 +28,5 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency "rspec-rails"
29
29
  spec.add_development_dependency "guard-rspec"
30
30
  spec.add_development_dependency "listen", "~> 3.0.0"
31
+ spec.add_development_dependency 'temping'
31
32
  end
@@ -11,13 +11,13 @@ module ActsAsTaggableArrayOn
11
11
  module ClassMethod
12
12
  def acts_as_taggable_array_on(*tag_def)
13
13
  tag_name = tag_def.first
14
- tag_array_type = TYPE_MATCHER[columns_hash[tag_name.to_s].type]
14
+ tag_array_type = TYPE_MATCHER[columns_hash[tag_name.to_s].try(:type)]
15
15
  parser = ActsAsTaggableArrayOn.parser
16
16
 
17
- scope :"with_any_#{tag_name}", ->(tags){ where("#{tag_name} && ARRAY[?]::#{tag_array_type}[]", parser.parse(tags)) }
18
- scope :"with_all_#{tag_name}", ->(tags){ where("#{tag_name} @> ARRAY[?]::#{tag_array_type}[]", parser.parse(tags)) }
19
- scope :"without_any_#{tag_name}", ->(tags){ where.not("#{tag_name} && ARRAY[?]::#{tag_array_type}[]", parser.parse(tags)) }
20
- scope :"without_all_#{tag_name}", ->(tags){ where.not("#{tag_name} @> ARRAY[?]::#{tag_array_type}[]", parser.parse(tags)) }
17
+ scope :"with_any_#{tag_name}", ->(tags){ where("#{table_name}.#{tag_name} && ARRAY[?]::#{tag_array_type}[]", parser.parse(tags)) }
18
+ scope :"with_all_#{tag_name}", ->(tags){ where("#{table_name}.#{tag_name} @> ARRAY[?]::#{tag_array_type}[]", parser.parse(tags)) }
19
+ scope :"without_any_#{tag_name}", ->(tags){ where.not("#{table_name}.#{tag_name} && ARRAY[?]::#{tag_array_type}[]", parser.parse(tags)) }
20
+ scope :"without_all_#{tag_name}", ->(tags){ where.not("#{table_name}.#{tag_name} @> ARRAY[?]::#{tag_array_type}[]", parser.parse(tags)) }
21
21
 
22
22
  self.class.class_eval do
23
23
  define_method :"all_#{tag_name}" do |options = {}, &block|
@@ -1,3 +1,3 @@
1
1
  module ActsAsTagPgarray
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5"
3
3
  end
@@ -11,6 +11,18 @@ describe ActsAsTaggableArrayOn::Taggable do
11
11
  User.acts_as_taggable_array_on :codes
12
12
  end
13
13
 
14
+
15
+ context "without database table" do
16
+ it "doesn't fail on class method call" do
17
+ Temping.create :dummy
18
+
19
+ class Dummy < ActiveRecord::Base; end
20
+ Dummy.acts_as_taggable_array_on :tags
21
+
22
+ Temping.teardown
23
+ end
24
+ end
25
+
14
26
  describe "#acts_as_taggable_array_on" do
15
27
  it "defines named scope to match any tags" do
16
28
  expect(User).to respond_to(:with_any_colors)
@@ -26,6 +38,20 @@ describe ActsAsTaggableArrayOn::Taggable do
26
38
  end
27
39
  end
28
40
 
41
+ it 'should define table name un-ambiguously' do
42
+ sql = User.with_any_sizes(['small']).to_sql
43
+ expect(sql).to eql("SELECT \"users\".* FROM \"users\" WHERE (users.sizes && ARRAY['small']::text[])")
44
+
45
+ sql = User.with_all_sizes(['small']).to_sql
46
+ expect(sql).to eql("SELECT \"users\".* FROM \"users\" WHERE (users.sizes @> ARRAY['small']::text[])")
47
+
48
+ sql = User.without_any_sizes(['small']).to_sql
49
+ expect(sql).to eql("SELECT \"users\".* FROM \"users\" WHERE (NOT (users.sizes && ARRAY['small']::text[]))")
50
+
51
+ sql = User.without_all_sizes(['small']).to_sql
52
+ expect(sql).to eql("SELECT \"users\".* FROM \"users\" WHERE (NOT (users.sizes @> ARRAY['small']::text[]))")
53
+ end
54
+
29
55
  it "should work with ::text typed array" do
30
56
  expect(User.with_any_sizes(['small'])).to match_array([@user2,@user3])
31
57
  expect(User.with_all_sizes(['small', 'large'])).to match_array([@user2,@user3])
@@ -2,6 +2,7 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'rspec'
4
4
  require 'active_record/railtie'
5
+ require 'temping'
5
6
  ActiveRecord::Base.logger = Logger.new(STDERR)
6
7
  ActiveRecord::Base.logger.level = 3
7
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts-as-taggable-array-on
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: '0.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takuya Miyamoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-26 00:00:00.000000000 Z
11
+ date: 2018-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: 3.0.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: temping
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  description: Simple tagging gem for Rails using postgres array.
126
140
  email:
127
141
  - miyamototakuya@gmail.com
@@ -129,6 +143,7 @@ executables: []
129
143
  extensions: []
130
144
  extra_rdoc_files: []
131
145
  files:
146
+ - ".editorconfig"
132
147
  - ".gitignore"
133
148
  - ".travis.yml"
134
149
  - Gemfile
@@ -167,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
182
  version: '0'
168
183
  requirements: []
169
184
  rubyforge_project:
170
- rubygems_version: 2.6.14
185
+ rubygems_version: 2.7.6
171
186
  signing_key:
172
187
  specification_version: 4
173
188
  summary: Simple tagging gem for Rails using postgres array.