flag_shih_tzu 0.3.22 → 0.3.23

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
  SHA256:
3
- metadata.gz: 5e43199789d6c30b71d15139ed647229e02f49116c45c4f4b7780b1d8a37f8b2
4
- data.tar.gz: 7d5616a0535b314704e7d71420d2bbd3f3075e1aafd9a0ee9a77f8ab7974a425
3
+ metadata.gz: 73b78e54263e309fa419f5f889f07c9c9facae95452a46af2fffbccfba1184e7
4
+ data.tar.gz: 0455055c99358352e6815729f0db5333f5d576cdb9171c5b4f2dd99aa43a0597
5
5
  SHA512:
6
- metadata.gz: b7e2245c742d73eaa3b9099fee558f276d18507e65f079b951a23d170ded6128564b72a1a94aaa89556b5b34241891128f6bd702f41e05b8ea1b36de6f44d239
7
- data.tar.gz: 4dd8a47b5730c3ace7e6ae611efeaad46e4a983d4d7a0e01fe94c35e41fc945e09244fef47d15a49ca64ab8ce0b8cf5983c8055e577c8d13697ff7989c56adab
6
+ metadata.gz: e5d7d736d8e0b40393a9950b3e21e8d24528ed8317fed223aa812475e2caee2192c03b125ecb02c2c99a5a5782b953e32100bcac445b62cb21cb6a1c76339ab0
7
+ data.tar.gz: 4a755282353388f95875bea8208879fe8961cab100204437b0054de955c84379dcd856226f317bf1945cdf9cc7930752d8f9bd68f040194d8d128faeb915315d
@@ -2,6 +2,10 @@
2
2
 
3
3
  * Work merged into master branch goes here until it is released.
4
4
 
5
+ # Version 0.3.23 - NOV.30.2018
6
+
7
+ * Avoid establishing a database connection unless necessary by Jonathan del Strother
8
+
5
9
  # Version 0.3.22 - SEP.18.2018
6
10
 
7
11
  * When #selected_flags= passed with nil it clears flag bits, by xpol
@@ -22,14 +22,6 @@ module FlagShihTzu
22
22
 
23
23
  module ClassMethods
24
24
  def has_flags(*args)
25
- if ActiveRecord::VERSION::STRING >= "4.1."
26
- begin
27
- connection
28
- rescue ActiveRecord::NoDatabaseError
29
- return
30
- end
31
- end
32
-
33
25
  flag_hash, opts = parse_flag_options(*args)
34
26
  opts =
35
27
  {
@@ -404,6 +396,15 @@ To turn off this warning set check_for_column: false in has_flags definition her
404
396
  end
405
397
 
406
398
  true
399
+
400
+ # Quietly ignore NoDatabaseErrors - presumably we're being run during, eg, `rails db:create`.
401
+ # NoDatabaseError was only introduced in Rails 4.1, which is why this error-handling is a bit convoluted.
402
+ rescue StandardError => e
403
+ if defined?(ActiveRecord::NoDatabaseError) && e.is_a?(ActiveRecord::NoDatabaseError)
404
+ true
405
+ else
406
+ raise
407
+ end
407
408
  end
408
409
 
409
410
  def sql_condition_for_flag(flag, colmn, enabled = true, custom_table_name = table_name)
@@ -1,3 +1,3 @@
1
1
  module FlagShihTzu
2
- VERSION = "0.3.22"
2
+ VERSION = "0.3.23"
3
3
  end
@@ -1226,6 +1226,53 @@ class FlagShihTzuInstanceMethodsTest < Test::Unit::TestCase
1226
1226
  assert SpaceshipWithNonIntegerColumn3.method_defined?(:warpdrive)
1227
1227
  end
1228
1228
 
1229
+ if ActiveRecord::VERSION::STRING >= "4.1."
1230
+ def test_should_ignore_database_missing_errors
1231
+ assert_nothing_raised do
1232
+ eval(<<-EOF
1233
+ class SpaceshipWithoutDatabaseConnection < ActiveRecord::Base
1234
+ def self.connection
1235
+ raise ActiveRecord::NoDatabaseError.new("Unknown database")
1236
+ end
1237
+ self.table_name ="spaceships"
1238
+ include FlagShihTzu
1239
+
1240
+ has_flags 1 => :warpdrive,
1241
+ 2 => :shields,
1242
+ 3 => :electrolytes
1243
+ end
1244
+ EOF
1245
+ )
1246
+ end
1247
+ assert SpaceshipWithoutDatabaseConnection.method_defined?(:warpdrive)
1248
+ end
1249
+ end
1250
+
1251
+ def test_shouldnt_establish_a_connection_if_check_for_column_is_false
1252
+ assert_nothing_raised do
1253
+ eval(<<-EOF
1254
+ class SpaceshipWithoutColumnCheck < ActiveRecord::Base
1255
+ cattr_accessor :connection_established
1256
+ def self.connection
1257
+ self.connection_established = true
1258
+ super
1259
+ end
1260
+ self.table_name ="spaceships"
1261
+ include FlagShihTzu
1262
+
1263
+ has_flags({
1264
+ 1 => :warpdrive,
1265
+ 2 => :shields,
1266
+ 3 => :electrolytes
1267
+ }, check_for_column: false)
1268
+ end
1269
+ EOF
1270
+ )
1271
+ end
1272
+ assert SpaceshipWithoutColumnCheck.method_defined?(:warpdrive)
1273
+ assert !SpaceshipWithoutColumnCheck.connection_established
1274
+ end
1275
+
1229
1276
  def test_column_guessing_for_default_column_2
1230
1277
  assert_equal "flags",
1231
1278
  @spaceship.class.determine_flag_colmn_for(:warpdrive)
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.22
4
+ version: 0.3.23
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: 2018-09-18 00:00:00.000000000 Z
15
+ date: 2018-11-30 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activerecord
@@ -110,7 +110,6 @@ executables:
110
110
  extensions: []
111
111
  extra_rdoc_files: []
112
112
  files:
113
- - ".DS_Store"
114
113
  - ".coveralls.yml"
115
114
  - ".gitignore"
116
115
  - ".travis.yml"
@@ -159,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
158
  version: '0'
160
159
  requirements: []
161
160
  rubyforge_project:
162
- rubygems_version: 2.7.7
161
+ rubygems_version: 2.7.8
163
162
  signing_key:
164
163
  specification_version: 4
165
164
  summary: Bit fields for ActiveRecord
data/.DS_Store DELETED
Binary file