acts-as-taggable-array-on 0.4.0 → 0.4.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: 571322f949adda3190c96102b3f5c5884aab591a
4
- data.tar.gz: 35675504cfeb7e6bba4bb2616da65403abe91904
3
+ metadata.gz: 9a9425d37517e5fe36a4248c6dc73d7b07f624ed
4
+ data.tar.gz: 7dfb8aba8ed94a45b021a386022e4817f06c015b
5
5
  SHA512:
6
- metadata.gz: cdf1581fb54a72305b93c52c09ce192bef5bb7b88dd6647a5e2be90e32a6c094a643c4475a5de44224c94ef894314f47bf25f34e35c8096f99d178fb1a811681
7
- data.tar.gz: 1ad9dbef4a56e0aca0de2e39c9af3bd6b263fe9a079893dc700fba14c11fa247492f4b83d08e25f69d09d3e083c5dd16870d467e62077dc24d7d6335e0cf14fe
6
+ metadata.gz: ced512be1adc28265254dab4f10950f3c14d537efd63d686b87c4a4282c427116ad7cc0666214a6b4dc1cd2e4ad716aaaec08ae459b351bd7736f3c7d7f2d524
7
+ data.tar.gz: 48fe26c163b62f53f243e053d677c1fe19a1cb9dfa3b434fa5fe78cfc3be6ae9be86b55afbbf72cd3c8c3e75f5af0933290366dde2f4ec9409d08a3c3f85563b
data/.travis.yml CHANGED
@@ -1,9 +1,11 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
4
- - 2.1.1
5
- - 2.2.2
6
- - 2.3.0
3
+ - 2.1.10
4
+ - 2.2.9
5
+ - 2.3.6
6
+ - 2.4.3
7
+ - 2.4.3
8
+ - 2.5.0
7
9
  addons:
8
10
  postgresql: 9.3
9
11
  gemfile:
@@ -17,9 +19,5 @@ script:
17
19
  - bundle exec rspec
18
20
  matrix:
19
21
  exclude:
20
- - rvm: 2.0.0
21
- gemfile: gemfiles/rails_5.gemfile
22
- - rvm: 2.1.1
23
- gemfile: gemfiles/rails_5.gemfile
24
- - rvm: 2.1.2
22
+ - rvm: 2.1.10
25
23
  gemfile: gemfiles/rails_5.gemfile
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_runtime_dependency 'activerecord', ['>= 4']
22
22
  spec.add_runtime_dependency 'activesupport', ['>= 4']
23
23
 
24
- spec.add_development_dependency 'pg'
24
+ spec.add_development_dependency 'pg', '~> 0.18'
25
25
 
26
26
  spec.add_development_dependency "bundler", "~> 1.5"
27
27
  spec.add_development_dependency "rake"
@@ -4,4 +4,4 @@ source 'https://rubygems.org'
4
4
  gemspec path: '../'
5
5
 
6
6
  gem 'activerecord', '~> 5.0.0'
7
- gem 'activesupport', '~> 5.0.0'
7
+ gem 'activesupport', '~> 5.0.0'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActsAsTaggableArrayOn
2
4
  class Parser
3
5
  def parse tags
@@ -1,18 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActsAsTaggableArrayOn
2
4
  module Taggable
3
5
  def self.included(base)
4
6
  base.extend(ClassMethod)
5
7
  end
6
8
 
9
+ TYPE_MATCHER = { string: 'varchar', text: 'text' }
10
+
7
11
  module ClassMethod
8
12
  def acts_as_taggable_array_on(*tag_def)
9
13
  tag_name = tag_def.first
14
+ tag_array_type = TYPE_MATCHER[columns_hash[tag_name.to_s].type]
10
15
  parser = ActsAsTaggableArrayOn.parser
11
16
 
12
- scope :"with_any_#{tag_name}", ->(tags){ where("#{tag_name} && ARRAY[?]::varchar[]", parser.parse(tags)) }
13
- scope :"with_all_#{tag_name}", ->(tags){ where("#{tag_name} @> ARRAY[?]::varchar[]", parser.parse(tags)) }
14
- scope :"without_any_#{tag_name}", ->(tags){ where.not("#{tag_name} && ARRAY[?]::varchar[]", parser.parse(tags)) }
15
- scope :"without_all_#{tag_name}", ->(tags){ where.not("#{tag_name} @> ARRAY[?]::varchar[]", parser.parse(tags)) }
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)) }
16
21
 
17
22
  self.class.class_eval do
18
23
  define_method :"all_#{tag_name}" do |options = {}, &block|
@@ -1,3 +1,3 @@
1
1
  module ActsAsTagPgarray
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -2,11 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  describe ActsAsTaggableArrayOn::Taggable do
4
4
  before do
5
- @user1 = User.create name: 'Tom', colors: ['red', 'blue']
6
- @user2 = User.create name: 'Ken', colors: ['black', 'white', 'red']
7
- @user3 = User.create name: 'Joe', colors: ['black', 'blue']
5
+ @user1 = User.create name: 'Tom', colors: ['red', 'blue'], sizes: ['medium', 'large']
6
+ @user2 = User.create name: 'Ken', colors: ['black', 'white', 'red'], sizes: ['small', 'large']
7
+ @user3 = User.create name: 'Joe', colors: ['black', 'blue'], sizes: ['small', 'medium', 'large']
8
8
 
9
9
  User.acts_as_taggable_array_on :colors
10
+ User.acts_as_taggable_array_on :sizes
10
11
  end
11
12
 
12
13
  describe "#acts_as_taggable_array_on" do
@@ -24,6 +25,13 @@ describe ActsAsTaggableArrayOn::Taggable do
24
25
  end
25
26
  end
26
27
 
28
+ it "should work with ::text typed array" do
29
+ expect(User.with_any_sizes(['small'])).to match_array([@user2,@user3])
30
+ expect(User.with_all_sizes(['small', 'large'])).to match_array([@user2,@user3])
31
+ expect(User.without_any_sizes('medium')).to match_array([@user2])
32
+ expect(User.without_all_sizes('medium')).to match_array([@user2])
33
+ end
34
+
27
35
  describe "#with_any_tags" do
28
36
  it "returns users having any tags of args" do
29
37
  expect(User.with_any_colors(['red', 'blue'])).to match_array([@user1,@user2,@user3])
data/spec/spec_helper.rb CHANGED
@@ -38,6 +38,7 @@ def create_database
38
38
  create_table :users do |t|
39
39
  t.string :name
40
40
  t.string :colors, array: true, default: []
41
+ t.text :sizes, array:true, default: []
41
42
  t.timestamps null: true
42
43
  end
43
44
  end
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.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takuya Miyamoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-24 00:00:00.000000000 Z
11
+ date: 2018-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: pg
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '0.18'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '0.18'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  version: '0'
168
168
  requirements: []
169
169
  rubyforge_project:
170
- rubygems_version: 2.5.1
170
+ rubygems_version: 2.6.14
171
171
  signing_key:
172
172
  specification_version: 4
173
173
  summary: Simple tagging gem for Rails using postgres array.