flag_shih_tzu 0.3.16 → 0.3.17

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: 39ff897d847cf4dafdfc34e7a3d725aa6d101b77
4
- data.tar.gz: 862c9a6441b3ec33d4f3cf0929935faf898efde7
3
+ metadata.gz: cd4bfc174291e12f105c3c1c94feef99ac5310cf
4
+ data.tar.gz: 1e92b592f783e0b6add71e02a6ece2e6a4a50046
5
5
  SHA512:
6
- metadata.gz: 2e3a221af865774a094c4135b9621953ac33fcca96b2b2d2b0aeab0947dd873886a15078f6d4d34a07f37e9ef00ad9dba04af99bc72edc3c236721b7b73db127
7
- data.tar.gz: bf1da90dcee4a170fdba40c179601d404351ee8f6d3debc45883d8d7cea038021d19b912ab1cab689cf37e6340c034bdb80d3c1839a0ee85a6778df69ef53461
6
+ metadata.gz: 2c92950fa9f20f53e38364cca772ba9ea3f0d9715fcb6899ad25eec25f1057ed4cce044158af77b17d020c2f36b05df54a34e0546b508115931566eb0a586610
7
+ data.tar.gz: e45040c582157973233deb06a36ec0ddea4006c1985226acb5f7fa6f966f2a7875e4a767a479a76a3aa7e6330cf147c90c91eed3fbb6f0e1e7e5f8a2d6662855
data/.travis.yml CHANGED
@@ -2,12 +2,13 @@ language: ruby
2
2
  cache: bundler
3
3
  sudo: false
4
4
  rvm:
5
- - 1.9.3
6
- - 2.0.0
7
- - 2.1.7
8
- - 2.2.3
5
+ - 1.9.3-p551
6
+ - 2.0.0-p648
7
+ - 2.1.10
8
+ - 2.2.7
9
+ - 2.3.4
10
+ - 2.4.1
9
11
  - ruby-head
10
- - jruby-1.7.22
11
12
  - jruby-9.0.1.0
12
13
  gemfile:
13
14
  - gemfiles/Gemfile.activerecord-2.3.x
@@ -17,10 +18,11 @@ gemfile:
17
18
  - gemfiles/Gemfile.activerecord-4.0.x
18
19
  - gemfiles/Gemfile.activerecord-4.1.x
19
20
  - gemfiles/Gemfile.activerecord-4.2.x
21
+ - gemfiles/Gemfile.activerecord-5.0.x
20
22
  matrix:
21
23
  allow_failures:
22
24
  - rvm: ruby-head
23
- - rvm: 1.9.3
25
+ - rvm: 1.9.3-p551
24
26
  exclude:
25
27
  - rvm: jruby-9.0.1.0
26
28
  gemfile: gemfiles/Gemfile.activerecord-2.3.x
@@ -32,39 +34,63 @@ matrix:
32
34
  gemfile: gemfiles/Gemfile.activerecord-3.2.x
33
35
  - rvm: jruby-9.0.1.0
34
36
  gemfile: gemfiles/Gemfile.activerecord-4.0.x
35
- - rvm: jruby-1.7.22
37
+ - rvm: jruby-9.0.1.0
38
+ gemfile: gemfiles/Gemfile.activerecord-5.0.x
39
+
40
+ - rvm: 2.4.1
41
+ gemfile: gemfiles/Gemfile.activerecord-2.3.x
42
+ - rvm: 2.4.1
43
+ gemfile: gemfiles/Gemfile.activerecord-3.0.x
44
+ - rvm: 2.4.1
45
+ gemfile: gemfiles/Gemfile.activerecord-3.1.x
46
+ - rvm: 2.4.1
47
+ gemfile: gemfiles/Gemfile.activerecord-3.2.x
48
+ - rvm: 2.4.1
49
+ gemfile: gemfiles/Gemfile.activerecord-4.0.x
50
+
51
+ - rvm: 2.3.4
36
52
  gemfile: gemfiles/Gemfile.activerecord-2.3.x
37
- - rvm: jruby-1.7.22
53
+ - rvm: 2.3.4
38
54
  gemfile: gemfiles/Gemfile.activerecord-3.0.x
39
- - rvm: jruby-1.7.22
55
+ - rvm: 2.3.4
40
56
  gemfile: gemfiles/Gemfile.activerecord-3.1.x
41
- - rvm: jruby-1.7.22
57
+ - rvm: 2.3.4
42
58
  gemfile: gemfiles/Gemfile.activerecord-3.2.x
43
- - rvm: jruby-1.7.22
59
+ - rvm: 2.3.4
44
60
  gemfile: gemfiles/Gemfile.activerecord-4.0.x
45
- - rvm: 2.2.3
61
+
62
+ - rvm: 2.2.7
46
63
  gemfile: gemfiles/Gemfile.activerecord-2.3.x
47
- - rvm: 2.2.3
64
+ - rvm: 2.2.7
48
65
  gemfile: gemfiles/Gemfile.activerecord-3.0.x
49
- - rvm: 2.2.3
66
+ - rvm: 2.2.7
50
67
  gemfile: gemfiles/Gemfile.activerecord-3.1.x
51
- - rvm: 2.2.3
68
+ - rvm: 2.2.7
52
69
  gemfile: gemfiles/Gemfile.activerecord-3.2.x
53
- - rvm: 2.2.3
70
+ - rvm: 2.2.7
54
71
  gemfile: gemfiles/Gemfile.activerecord-4.0.x
55
- - rvm: 2.1.7
72
+
73
+ - rvm: 2.1.10
56
74
  gemfile: gemfiles/Gemfile.activerecord-2.3.x
57
- - rvm: 2.1.7
75
+ - rvm: 2.1.10
58
76
  gemfile: gemfiles/Gemfile.activerecord-3.0.x
59
- - rvm: 2.1.7
77
+ - rvm: 2.1.10
60
78
  gemfile: gemfiles/Gemfile.activerecord-3.1.x
61
- - rvm: 2.0.0
79
+ - rvm: 2.1.10
80
+ gemfile: gemfiles/Gemfile.activerecord-5.0.x
81
+
82
+ - rvm: 2.0.0-p648
62
83
  gemfile: gemfiles/Gemfile.activerecord-2.3.x
63
- - rvm: 2.0.0
84
+ - rvm: 2.0.0-p648
64
85
  gemfile: gemfiles/Gemfile.activerecord-4.2.x
65
- - rvm: 1.9.3
86
+ - rvm: 2.0.0-p648
87
+ gemfile: gemfiles/Gemfile.activerecord-5.0.x
88
+
89
+ - rvm: 1.9.3-p551
90
+ gemfile: gemfiles/Gemfile.activerecord-5.0.x
91
+ - rvm: 1.9.3-p551
66
92
  gemfile: gemfiles/Gemfile.activerecord-4.2.x
67
- - rvm: 1.9.3
93
+ - rvm: 1.9.3-p551
68
94
  gemfile: gemfiles/Gemfile.activerecord-4.1.x
69
- - rvm: 1.9.3
95
+ - rvm: 1.9.3-p551
70
96
  gemfile: gemfiles/Gemfile.activerecord-4.0.x
data/README.md CHANGED
@@ -17,7 +17,7 @@ Bit fields for ActiveRecord
17
17
  | homepage | [https://github.com/pboling/flag_shih_tzu][homepage] |
18
18
  | documentation | [http://rdoc.info/github/pboling/flag_shih_tzu/frames][documentation] |
19
19
  | live chat | [![Join the chat at https://gitter.im/pboling/flag_shih_tzu](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/pboling/flag_shih_tzu?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) |
20
- | Spread ~♡ⓛⓞⓥⓔ♡~ | [on Coderbits](https://coderbits.com/pboling), [on Coderwall](http://coderwall.com/pboling) |
20
+ | Spread ~♡ⓛⓞⓥⓔ♡~ | [on AngelList](https://angel.co/peter-boling), [on Coderwall](http://coderwall.com/pboling) |
21
21
 
22
22
  ## Summary
23
23
 
@@ -49,21 +49,24 @@ What is a ["Shih Tzu"](http://en.wikipedia.org/wiki/Shih_Tzu)?
49
49
  The gem is actively being tested with:
50
50
 
51
51
  * MySQL, PostgreSQL and SQLite3 databases (Both Ruby and JRuby adapters)
52
- * ActiveRecord versions 2.3.x, 3.0.x, 3.1.x, 3.2.x, 4.0.x, 4.1.x, 4.2.x
53
- * Ruby 1.9.3, 2.0.0, 2.1.7, 2.2.3, jruby-1.7.22, jruby-9.0.1.0
52
+ * ActiveRecord versions 2.3.x, 3.0.x, 3.1.x, 3.2.x, 4.0.x, 4.1.x, 4.2.x, 5.0.x
53
+ * Ruby 1.9.3, 2.0.0, 2.1.10, 2.2.7, 2.3.4, 2.4.1, jruby-1.7.22, jruby-9.0.1.0, and ruby-head
54
54
  * Travis tests the supportedt builds. See [.travis.yml](https://github.com/pboling/flag_shih_tzu/blob/master/.travis.yml) for the matrix.
55
55
  * All of the supported builds can also be run locally. See [bin/test.bash](https://github.com/pboling/flag_shih_tzu/blob/master/bin/test.bash)
56
56
 
57
57
  ### Compatibility Matrix
58
58
 
59
- | Ruby / Active Record | 2.3.x | 3.0.x | 3.1.x | 3.2.x | 4.0.x | 4.1.x | 4.2.x |
60
- |:---------------------:|:-----:|:-----:|:-----:|:-----:|:-----:|:-----:|:-----:|
61
- | 1.9.3 | ✓ | ✓ | ✓ | ✓ | | | |
62
- | 2.0.0 | | ✓ | ✓ | ✓ | ✓ | ✓ | |
63
- | 2.1.x | | | | ✓ | ✓ | ✓ | ✓ |
64
- | 2.2.x | | | | ✓ | ✓ | ✓ | ✓ |
65
- | jruby-1.7.x | | | ✓ | ✓ | ✓ | ✓ | ✓ |
66
- | jruby-9.0.x | | | | ✓ | ✓ | ✓ | ✓ |
59
+ | Ruby / Active Record | 2.3.x | 3.0.x | 3.1.x | 3.2.x | 4.0.x | 4.1.x | 4.2.x | 5.0.x |
60
+ |:---------------------:|:-----:|:-----:|:-----:|:-----:|:-----:|:-----:|:-----:|:-----:|
61
+ | 1.9.3 | ✓ | ✓ | ✓ | ✓ | | | | |
62
+ | 2.0.0 | | ✓ | ✓ | ✓ | ✓ | ✓ | | |
63
+ | 2.1.x | | | | ✓ | ✓ | ✓ | ✓ | |
64
+ | 2.2.0-2.2.1 | | | | ✓ | ✓ | ✓ | ✓ | |
65
+ | 2.2.2+ | | | | ✓ | ✓ | ✓ | ✓ | ✓ |
66
+ | 2.3.x | | | | ✓ | ✓ | ✓ | ✓ | ✓ |
67
+ | 2.4.x | | | | | | | ✓ | ✓ |
68
+ | jruby-1.7.x | | | ✓ | ✓ | ✓ | ✓ | ✓ | |
69
+ | jruby-9.0.x | | | | ✓ | ✓ | ✓ | ✓ | ✓ |
67
70
 
68
71
  **Legacy**
69
72
 
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec :path => ".."
4
+
5
+ gem "activerecord", "~> 5.0.0"
6
+ gem "sqlite3", "~> 1.3", :platforms => [:ruby]
7
+ gem "activerecord-jdbcsqlite3-adapter", :platforms => [:jruby]
8
+ gem "activerecord-mysql2-adapter", :platforms => [:ruby]
9
+ gem "activerecord-jdbcmysql-adapter", :platforms => [:jruby]
10
+ gem "pg", :platforms => [:ruby_18]
11
+ gem "activerecord-jdbcpostgresql-adapter", :platforms => [:jruby]
12
+
13
+ gem "reek", "~> 3.5.0", :platforms => [:ruby]
14
+ gem "roodi", "~> 5.0.0", :platforms => [:ruby]
data/lib/flag_shih_tzu.rb CHANGED
@@ -278,7 +278,7 @@ To turn off this warning set check_for_column: false in has_flags definition her
278
278
  end
279
279
 
280
280
  def chained_flags_condition(colmn = DEFAULT_COLUMN_NAME, *args)
281
- %[(#{table_name}.#{colmn} in (#{chained_flags_values(colmn, *args).join(",")}))]
281
+ %[(#{flag_full_column_name(table_name, colmn)} in (#{chained_flags_values(colmn, *args).join(",")}))]
282
282
  end
283
283
 
284
284
  def flag_keys(colmn = DEFAULT_COLUMN_NAME)
@@ -287,6 +287,19 @@ To turn off this warning set check_for_column: false in has_flags definition her
287
287
 
288
288
  private
289
289
 
290
+ def flag_full_column_name(table, column)
291
+ "#{connection.quote_table_name(table)}.#{connection.quote_column_name(column)}"
292
+ end
293
+
294
+ def flag_full_column_name_for_assignment(table, column)
295
+ if (ActiveRecord::VERSION::MAJOR <= 3)
296
+ # If you're trying to do multi-table updates with Rails < 4, sorry - you're out of luck.
297
+ connection.quote_column_name(column)
298
+ else
299
+ connection.quote_table_name_for_assignment(table, column)
300
+ end
301
+ end
302
+
290
303
  def flag_value_range_for_column(colmn)
291
304
  max = flag_mapping[colmn].values.max
292
305
  Range.new(0, (2 * max) - 1)
@@ -296,7 +309,7 @@ To turn off this warning set check_for_column: false in has_flags definition her
296
309
  val = flag_value_range_for_column(colmn).to_a
297
310
  args.each do |flag|
298
311
  neg = false
299
- if flag.to_s.match /^not_/
312
+ if flag.to_s.match(/^not_/)
300
313
  neg = true
301
314
  flag = flag.to_s.sub(/^not_/, "").to_sym
302
315
  end
@@ -335,7 +348,15 @@ To turn off this warning set check_for_column: false in has_flags definition her
335
348
  has_ar = (!!defined?(ActiveRecord) && respond_to?(:descends_from_active_record?))
336
349
  # Supposedly Rails 2.3 takes care of this, but this precaution
337
350
  # is needed for backwards compatibility
338
- has_table = has_ar ? connection.tables.include?(custom_table_name) : true
351
+ has_table = if has_ar
352
+ if ::ActiveRecord::VERSION::MAJOR >= 5
353
+ connection.data_sources
354
+ else
355
+ connection.tables.include?(custom_table_name)
356
+ end
357
+ else
358
+ true
359
+ end
339
360
  if has_table
340
361
  found_column = columns.detect { |column| column.name == colmn }
341
362
  # If you have not yet run the migration that adds the 'flags' column
@@ -370,13 +391,13 @@ To turn off this warning set check_for_column: false in has_flags definition her
370
391
  if flag_options[colmn][:flag_query_mode] == :bit_operator
371
392
  # use & bit operator directly in the SQL query.
372
393
  # This has the drawback of not using an index on the flags colum.
373
- %[(#{custom_table_name}.#{colmn} & #{flag_mapping[colmn][flag]} = #{enabled ? flag_mapping[colmn][flag] : 0})]
394
+ %[(#{flag_full_column_name(custom_table_name, colmn)} & #{flag_mapping[colmn][flag]} = #{enabled ? flag_mapping[colmn][flag] : 0})]
374
395
  elsif flag_options[colmn][:flag_query_mode] == :in_list
375
396
  # use IN() operator in the SQL query.
376
397
  # This has the drawback of becoming a big query
377
398
  # when you have lots of flags.
378
399
  neg = enabled ? "" : "not "
379
- %[(#{custom_table_name}.#{colmn} #{neg}in (#{sql_in_for_flag(flag, colmn).join(",")}))]
400
+ %[(#{flag_full_column_name(custom_table_name, colmn)} #{neg}in (#{sql_in_for_flag(flag, colmn).join(",")}))]
380
401
  else
381
402
  raise NoSuchFlagQueryModeException
382
403
  end
@@ -390,8 +411,9 @@ To turn off this warning set check_for_column: false in has_flags definition her
390
411
 
391
412
  def sql_set_for_flag(flag, colmn, enabled = true, custom_table_name = table_name)
392
413
  check_flag(flag, colmn)
393
- full_name = "#{custom_table_name}.#{colmn}"
394
- "#{full_name} = #{full_name} #{enabled ? "| " : "& ~" }#{flag_mapping[colmn][flag]}"
414
+ lhs_name = flag_full_column_name_for_assignment(custom_table_name, colmn)
415
+ rhs_name = flag_full_column_name(custom_table_name, colmn)
416
+ "#{lhs_name} = #{rhs_name} #{enabled ? "| " : "& ~" }#{flag_mapping[colmn][flag]}"
395
417
  end
396
418
 
397
419
  def valid_flag_key?(flag_key)
@@ -578,5 +600,4 @@ To turn off this warning set check_for_column: false in has_flags definition her
578
600
  def determine_flag_colmn_for(flag)
579
601
  self.class.determine_flag_colmn_for(flag)
580
602
  end
581
-
582
603
  end
@@ -1,3 +1,3 @@
1
1
  module FlagShihTzu
2
- VERSION = "0.3.16"
2
+ VERSION = "0.3.17"
3
3
  end
@@ -269,55 +269,55 @@ class FlagShihTzuClassMethodsTest < Test::Unit::TestCase
269
269
  end
270
270
 
271
271
  def test_should_define_a_sql_condition_method_for_flag_enabled
272
- assert_equal "(spaceships.flags in (1,3,5,7))",
272
+ assert_equal '("spaceships"."flags" in (1,3,5,7))',
273
273
  Spaceship.warpdrive_condition
274
- assert_equal "(spaceships.flags in (2,3,6,7))",
274
+ assert_equal '("spaceships"."flags" in (2,3,6,7))',
275
275
  Spaceship.shields_condition
276
- assert_equal "(spaceships.flags in (4,5,6,7))",
276
+ assert_equal '("spaceships"."flags" in (4,5,6,7))',
277
277
  Spaceship.electrolytes_condition
278
278
  end
279
279
 
280
280
  def test_should_define_a_sql_condition_method_for_flag_enabled_with_missing_flags
281
- assert_equal "(spaceships.flags in (1,3,5,7))",
281
+ assert_equal '("spaceships"."flags" in (1,3,5,7))',
282
282
  SpaceshipWithMissingFlags.warpdrive_condition
283
- assert_equal "(spaceships.flags in (4,5,6,7))",
283
+ assert_equal '("spaceships"."flags" in (4,5,6,7))',
284
284
  SpaceshipWithMissingFlags.electrolytes_condition
285
285
  end
286
286
 
287
287
  def test_should_accept_a_table_alias_option_for_sql_condition_method
288
- assert_equal "(old_spaceships.flags in (1,3,5,7))",
288
+ assert_equal '("old_spaceships"."flags" in (1,3,5,7))',
289
289
  Spaceship.warpdrive_condition(table_alias: "old_spaceships")
290
290
  end
291
291
 
292
292
  def test_should_define_a_sql_condition_method_for_flag_enabled_with_2_colmns
293
- assert_equal "(spaceships_with_2_custom_flags_column.bits in (1,3))",
293
+ assert_equal '("spaceships_with_2_custom_flags_column"."bits" in (1,3))',
294
294
  SpaceshipWith2CustomFlagsColumn.warpdrive_condition
295
- assert_equal "(spaceships_with_2_custom_flags_column.bits in (2,3))",
295
+ assert_equal '("spaceships_with_2_custom_flags_column"."bits" in (2,3))',
296
296
  SpaceshipWith2CustomFlagsColumn.hyperspace_condition
297
- assert_equal "(spaceships_with_2_custom_flags_column.commanders in (1,3))",
297
+ assert_equal '("spaceships_with_2_custom_flags_column"."commanders" in (1,3))',
298
298
  SpaceshipWith2CustomFlagsColumn.jeanlucpicard_condition
299
- assert_equal "(spaceships_with_2_custom_flags_column.commanders in (2,3))",
299
+ assert_equal '("spaceships_with_2_custom_flags_column"."commanders" in (2,3))',
300
300
  SpaceshipWith2CustomFlagsColumn.dajanatroj_condition
301
301
  end
302
302
 
303
303
  def test_should_define_a_sql_condition_method_for_flag_not_enabled
304
- assert_equal "(spaceships.flags not in (1,3,5,7))",
304
+ assert_equal '("spaceships"."flags" not in (1,3,5,7))',
305
305
  Spaceship.not_warpdrive_condition
306
- assert_equal "(spaceships.flags not in (2,3,6,7))",
306
+ assert_equal '("spaceships"."flags" not in (2,3,6,7))',
307
307
  Spaceship.not_shields_condition
308
- assert_equal "(spaceships.flags not in (4,5,6,7))",
308
+ assert_equal '("spaceships"."flags" not in (4,5,6,7))',
309
309
  Spaceship.not_electrolytes_condition
310
310
  end
311
311
 
312
312
  def test_should_define_a_sql_condition_method_for_flag_not_enabled_with_missing_flags
313
- assert_equal "(spaceships.flags not in (1,3,5,7))",
313
+ assert_equal '("spaceships"."flags" not in (1,3,5,7))',
314
314
  SpaceshipWithMissingFlags.not_warpdrive_condition
315
- assert_equal "(spaceships.flags not in (4,5,6,7))",
315
+ assert_equal '("spaceships"."flags" not in (4,5,6,7))',
316
316
  SpaceshipWithMissingFlags.not_electrolytes_condition
317
317
  end
318
318
 
319
319
  def test_sql_condition_for_flag_with_custom_table_name_and_default_query_mode
320
- assert_equal "(custom_spaceships.flags in (1,3,5,7))",
320
+ assert_equal '("custom_spaceships"."flags" in (1,3,5,7))',
321
321
  Spaceship.send(:sql_condition_for_flag,
322
322
  :warpdrive,
323
323
  "flags",
@@ -325,7 +325,7 @@ class FlagShihTzuClassMethodsTest < Test::Unit::TestCase
325
325
  "custom_spaceships")
326
326
  end
327
327
  def test_sql_condition_for_flag_with_in_list_query_mode
328
- assert_equal "(spaceships.flags in (1,3))",
328
+ assert_equal '("spaceships"."flags" in (1,3))',
329
329
  SpaceshipWithInListQueryMode.send(:sql_condition_for_flag,
330
330
  :warpdrive,
331
331
  "flags",
@@ -333,7 +333,7 @@ class FlagShihTzuClassMethodsTest < Test::Unit::TestCase
333
333
  "spaceships")
334
334
  end
335
335
  def test_sql_condition_for_flag_with_bit_operator_query_mode
336
- assert_equal "(spaceships.flags & 1 = 1)",
336
+ assert_equal '("spaceships"."flags" & 1 = 1)',
337
337
  SpaceshipWithBitOperatorQueryMode.send(:sql_condition_for_flag,
338
338
  :warpdrive,
339
339
  "flags",
@@ -345,50 +345,50 @@ class FlagShihTzuClassMethodsTest < Test::Unit::TestCase
345
345
  Spaceship.send(:sql_in_for_flag, :warpdrive, "flags")
346
346
  end
347
347
  def test_sql_set_for_flag
348
- assert_equal "spaceships.flags = spaceships.flags | 1",
348
+ assert_equal '"flags" = "spaceships"."flags" | 1',
349
349
  Spaceship.send(:sql_set_for_flag, :warpdrive, "flags")
350
350
  end
351
351
 
352
352
  def test_should_define_a_sql_condition_method_for_flag_enabled_with_2_colmns_not_enabled
353
- assert_equal "(spaceships_with_2_custom_flags_column.bits not in (1,3))",
353
+ assert_equal '("spaceships_with_2_custom_flags_column"."bits" not in (1,3))',
354
354
  SpaceshipWith2CustomFlagsColumn.not_warpdrive_condition
355
- assert_equal "(spaceships_with_2_custom_flags_column.bits not in (2,3))",
355
+ assert_equal '("spaceships_with_2_custom_flags_column"."bits" not in (2,3))',
356
356
  SpaceshipWith2CustomFlagsColumn.not_hyperspace_condition
357
- assert_equal "(spaceships_with_2_custom_flags_column.commanders not in (1,3))",
357
+ assert_equal '("spaceships_with_2_custom_flags_column"."commanders" not in (1,3))',
358
358
  SpaceshipWith2CustomFlagsColumn.not_jeanlucpicard_condition
359
- assert_equal "(spaceships_with_2_custom_flags_column.commanders not in (2,3))",
359
+ assert_equal '("spaceships_with_2_custom_flags_column"."commanders" not in (2,3))',
360
360
  SpaceshipWith2CustomFlagsColumn.not_dajanatroj_condition
361
361
  end
362
362
 
363
363
  def test_should_define_a_sql_condition_method_for_flag_enabled_using_bit_operators
364
- assert_equal "(spaceships.flags & 1 = 1)",
364
+ assert_equal '("spaceships"."flags" & 1 = 1)',
365
365
  SpaceshipWithBitOperatorQueryMode.warpdrive_condition
366
- assert_equal "(spaceships.flags & 2 = 2)",
366
+ assert_equal '("spaceships"."flags" & 2 = 2)',
367
367
  SpaceshipWithBitOperatorQueryMode.shields_condition
368
368
  end
369
369
 
370
370
  def test_should_define_a_sql_condition_method_for_flag_not_enabled_using_bit_operators
371
- assert_equal "(spaceships.flags & 1 = 0)",
371
+ assert_equal '("spaceships"."flags" & 1 = 0)',
372
372
  SpaceshipWithBitOperatorQueryMode.not_warpdrive_condition
373
- assert_equal "(spaceships.flags & 2 = 0)",
373
+ assert_equal '("spaceships"."flags" & 2 = 0)',
374
374
  SpaceshipWithBitOperatorQueryMode.not_shields_condition
375
375
  end
376
376
 
377
377
  def test_should_define_a_named_scope_for_flag_enabled
378
- assert_where_value "(spaceships.flags in (1,3,5,7))",
378
+ assert_where_value '("spaceships"."flags" in (1,3,5,7))',
379
379
  Spaceship.warpdrive
380
- assert_where_value "(spaceships.flags in (2,3,6,7))",
380
+ assert_where_value '("spaceships"."flags" in (2,3,6,7))',
381
381
  Spaceship.shields
382
- assert_where_value "(spaceships.flags in (4,5,6,7))",
382
+ assert_where_value '("spaceships"."flags" in (4,5,6,7))',
383
383
  Spaceship.electrolytes
384
384
  end
385
385
 
386
386
  def test_should_define_a_named_scope_for_flag_not_enabled
387
- assert_where_value "(spaceships.flags not in (1,3,5,7))",
387
+ assert_where_value '("spaceships"."flags" not in (1,3,5,7))',
388
388
  Spaceship.not_warpdrive
389
- assert_where_value "(spaceships.flags not in (2,3,6,7))",
389
+ assert_where_value '("spaceships"."flags" not in (2,3,6,7))',
390
390
  Spaceship.not_shields
391
- assert_where_value "(spaceships.flags not in (4,5,6,7))",
391
+ assert_where_value '("spaceships"."flags" not in (4,5,6,7))',
392
392
  Spaceship.not_electrolytes
393
393
  end
394
394
 
@@ -398,38 +398,38 @@ class FlagShihTzuClassMethodsTest < Test::Unit::TestCase
398
398
  end
399
399
 
400
400
  def test_should_define_a_named_scope_for_flag_enabled_with_2_columns
401
- assert_where_value "(spaceships_with_2_custom_flags_column.bits in (1,3))",
401
+ assert_where_value '("spaceships_with_2_custom_flags_column"."bits" in (1,3))',
402
402
  SpaceshipWith2CustomFlagsColumn.warpdrive
403
- assert_where_value "(spaceships_with_2_custom_flags_column.bits in (2,3))",
403
+ assert_where_value '("spaceships_with_2_custom_flags_column"."bits" in (2,3))',
404
404
  SpaceshipWith2CustomFlagsColumn.hyperspace
405
- assert_where_value "(spaceships_with_2_custom_flags_column.commanders in (1,3))",
405
+ assert_where_value '("spaceships_with_2_custom_flags_column"."commanders" in (1,3))',
406
406
  SpaceshipWith2CustomFlagsColumn.jeanlucpicard
407
- assert_where_value "(spaceships_with_2_custom_flags_column.commanders in (2,3))",
407
+ assert_where_value '("spaceships_with_2_custom_flags_column"."commanders" in (2,3))',
408
408
  SpaceshipWith2CustomFlagsColumn.dajanatroj
409
409
  end
410
410
 
411
411
  def test_should_define_a_named_scope_for_flag_not_enabled_with_2_columns
412
- assert_where_value "(spaceships_with_2_custom_flags_column.bits not in (1,3))",
412
+ assert_where_value '("spaceships_with_2_custom_flags_column"."bits" not in (1,3))',
413
413
  SpaceshipWith2CustomFlagsColumn.not_warpdrive
414
- assert_where_value "(spaceships_with_2_custom_flags_column.bits not in (2,3))",
414
+ assert_where_value '("spaceships_with_2_custom_flags_column"."bits" not in (2,3))',
415
415
  SpaceshipWith2CustomFlagsColumn.not_hyperspace
416
- assert_where_value "(spaceships_with_2_custom_flags_column.commanders not in (1,3))",
416
+ assert_where_value '("spaceships_with_2_custom_flags_column"."commanders" not in (1,3))',
417
417
  SpaceshipWith2CustomFlagsColumn.not_jeanlucpicard
418
- assert_where_value "(spaceships_with_2_custom_flags_column.commanders not in (2,3))",
418
+ assert_where_value '("spaceships_with_2_custom_flags_column"."commanders" not in (2,3))',
419
419
  SpaceshipWith2CustomFlagsColumn.not_dajanatroj
420
420
  end
421
421
 
422
422
  def test_should_define_a_named_scope_for_flag_enabled_using_bit_operators
423
- assert_where_value "(spaceships.flags & 1 = 1)",
423
+ assert_where_value '("spaceships"."flags" & 1 = 1)',
424
424
  SpaceshipWithBitOperatorQueryMode.warpdrive
425
- assert_where_value "(spaceships.flags & 2 = 2)",
425
+ assert_where_value '("spaceships"."flags" & 2 = 2)',
426
426
  SpaceshipWithBitOperatorQueryMode.shields
427
427
  end
428
428
 
429
429
  def test_should_define_a_named_scope_for_flag_not_enabled_using_bit_operators
430
- assert_where_value "(spaceships.flags & 1 = 0)",
430
+ assert_where_value '("spaceships"."flags" & 1 = 0)',
431
431
  SpaceshipWithBitOperatorQueryMode.not_warpdrive
432
- assert_where_value "(spaceships.flags & 2 = 0)",
432
+ assert_where_value '("spaceships"."flags" & 2 = 0)',
433
433
  SpaceshipWithBitOperatorQueryMode.not_shields
434
434
  end
435
435
 
@@ -511,16 +511,16 @@ class FlagShihTzuClassMethodsTest < Test::Unit::TestCase
511
511
  end
512
512
 
513
513
  def test_should_return_the_correct_condition_with_chained_flags
514
- assert_equal "(spaceships.flags in (3,7))",
514
+ assert_equal '("spaceships"."flags" in (3,7))',
515
515
  Spaceship.chained_flags_condition("flags",
516
516
  :warpdrive,
517
517
  :shields)
518
- assert_equal "(spaceships.flags in (7))",
518
+ assert_equal '("spaceships"."flags" in (7))',
519
519
  Spaceship.chained_flags_condition("flags",
520
520
  :warpdrive,
521
521
  :shields,
522
522
  :electrolytes)
523
- assert_equal "(spaceships.flags in (2,6))",
523
+ assert_equal '("spaceships"."flags" in (2,6))',
524
524
  Spaceship.chained_flags_condition("flags",
525
525
  :not_warpdrive,
526
526
  :shields)
@@ -577,21 +577,21 @@ class FlagShihTzuClassMethodsTest < Test::Unit::TestCase
577
577
  spaceship.save!
578
578
  spaceship.reload
579
579
  assert_equal 3, spaceship.flags("bits")
580
- assert_equal "(spaceships_with_custom_flags_column.bits in (1,3))",
580
+ assert_equal '("spaceships_with_custom_flags_column"."bits" in (1,3))',
581
581
  SpaceshipWithCustomFlagsColumn.warpdrive_condition
582
- assert_equal "(spaceships_with_custom_flags_column.bits not in (1,3))",
582
+ assert_equal '("spaceships_with_custom_flags_column"."bits" not in (1,3))',
583
583
  SpaceshipWithCustomFlagsColumn.not_warpdrive_condition
584
- assert_equal "(spaceships_with_custom_flags_column.bits in (2,3))",
584
+ assert_equal '("spaceships_with_custom_flags_column"."bits" in (2,3))',
585
585
  SpaceshipWithCustomFlagsColumn.hyperspace_condition
586
- assert_equal "(spaceships_with_custom_flags_column.bits not in (2,3))",
586
+ assert_equal '("spaceships_with_custom_flags_column"."bits" not in (2,3))',
587
587
  SpaceshipWithCustomFlagsColumn.not_hyperspace_condition
588
- assert_where_value %[(spaceships_with_custom_flags_column.bits in (1,3))],
588
+ assert_where_value '("spaceships_with_custom_flags_column"."bits" in (1,3))',
589
589
  SpaceshipWithCustomFlagsColumn.warpdrive
590
- assert_where_value %[(spaceships_with_custom_flags_column.bits not in (1,3))],
590
+ assert_where_value '("spaceships_with_custom_flags_column"."bits" not in (1,3))',
591
591
  SpaceshipWithCustomFlagsColumn.not_warpdrive
592
- assert_where_value %[(spaceships_with_custom_flags_column.bits in (2,3))],
592
+ assert_where_value '("spaceships_with_custom_flags_column"."bits" in (2,3))',
593
593
  SpaceshipWithCustomFlagsColumn.hyperspace
594
- assert_where_value %[(spaceships_with_custom_flags_column.bits not in (2,3))],
594
+ assert_where_value '("spaceships_with_custom_flags_column"."bits" not in (2,3))',
595
595
  SpaceshipWithCustomFlagsColumn.not_hyperspace
596
596
  end
597
597
 
@@ -631,6 +631,8 @@ class FlagShihTzuClassMethodsTest < Test::Unit::TestCase
631
631
  def assert_where_value(expected, scope)
632
632
  actual = if ActiveRecord::VERSION::MAJOR == 2
633
633
  scope.proxy_options[:conditions]
634
+ elsif ActiveRecord::VERSION::MAJOR >= 5
635
+ scope.where_clause.ast.children.first.expr
634
636
  else
635
637
  scope.where_values.first
636
638
  end
@@ -1419,9 +1421,9 @@ class FlagShihTzuDerivedClassTest < Test::Unit::TestCase
1419
1421
  end
1420
1422
 
1421
1423
  def test_should_return_a_sql_set_method_for_flag
1422
- assert_equal "spaceships.flags = spaceships.flags | 1",
1424
+ assert_equal '"flags" = "spaceships"."flags" | 1',
1423
1425
  Spaceship.send(:sql_set_for_flag, :warpdrive, "flags", true)
1424
- assert_equal "spaceships.flags = spaceships.flags & ~1",
1426
+ assert_equal '"flags" = "spaceships"."flags" & ~1',
1425
1427
  Spaceship.send(:sql_set_for_flag, :warpdrive, "flags", false)
1426
1428
  end
1427
1429
 
data/test/schema.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  ActiveRecord::Schema.define(:version => 0) do
2
2
  create_table :spaceships, :force => true do |t|
3
- t.string :type, :null => false, :default => 'Spaceship'
4
3
  t.integer :flags, :null => false, :default => 0
5
4
  t.string :incorrect_flags_column, :null => false, :default => ''
6
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flag_shih_tzu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.16
4
+ version: 0.3.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Boling
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2017-01-16 00:00:00.000000000 Z
15
+ date: 2017-04-29 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activerecord
@@ -129,6 +129,7 @@ files:
129
129
  - gemfiles/Gemfile.activerecord-4.0.x
130
130
  - gemfiles/Gemfile.activerecord-4.1.x
131
131
  - gemfiles/Gemfile.activerecord-4.2.x
132
+ - gemfiles/Gemfile.activerecord-5.0.x
132
133
  - lib/flag_shih_tzu.rb
133
134
  - lib/flag_shih_tzu/validators.rb
134
135
  - lib/flag_shih_tzu/version.rb
@@ -156,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
157
  version: '0'
157
158
  requirements: []
158
159
  rubyforge_project:
159
- rubygems_version: 2.6.8
160
+ rubygems_version: 2.4.8
160
161
  signing_key:
161
162
  specification_version: 4
162
163
  summary: Bit fields for ActiveRecord