validates_type 0.1.0 → 1.0.0

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
2
  SHA1:
3
- metadata.gz: f49fb46c37a3674822b3d22fa2419aaf4c0fe481
4
- data.tar.gz: dea07a48bc5642340721e3503423de1c4b7fe9e1
3
+ metadata.gz: 4369f65c87acc073e858ab748631f194ec40c63d
4
+ data.tar.gz: d2fd07275a4fb65f8fa988b5d363aa201b855953
5
5
  SHA512:
6
- metadata.gz: 18aada637c9cb2671fa7c1be8ff377f867df2802740b7022f2e548bc0a5958094e0de0576f98c41e1a6e758ddb78289d3cf07e672dbe70e4e64ba8cc5bf1a0d2
7
- data.tar.gz: 4455148f55376189879f6e899de21447deeca450baa7cc5fd0b55b2dcf565ef4d9f06f48d6847fe3ad9426e04d78724cdeaeb8d6b1e3a06e3bce03f627466415
6
+ metadata.gz: 6b90ab9bc7f9419181003a9b67a97c3506163edf44d88fc2762f10a4b5ab68018180f226f05775c372f87d25218aa0898a2c97fbe4fb72d37fc9c4cbbc95de40
7
+ data.tar.gz: 383f171865e3ebc1e1a3225e27949dacb5c1fc91760fd9e1f70a5ef1eff94e374e698e14a23a833e7893858438f5e425855f3c31d86d58fa6adae4cc35932978
@@ -83,15 +83,16 @@ module ActiveModel
83
83
  # return: class constant of supported types or raises UnsupportedType
84
84
  def symbol_class(symbol)
85
85
  @symbol_class ||= {
86
- :array => Array,
87
- :boolean => Boolean,
88
- :float => Float,
89
- :hash => Hash,
90
- :integer => Integer,
91
- :string => String,
92
- :symbol => Symbol,
93
- :time => Time,
94
- :date => Date,
86
+ :array => Array,
87
+ :boolean => Boolean,
88
+ :float => Float,
89
+ :hash => Hash,
90
+ :integer => Integer,
91
+ :string => String,
92
+ :symbol => Symbol,
93
+ :time => Time,
94
+ :date => Date,
95
+ :big_decimal => BigDecimal,
95
96
  }[symbol] || fail(ValidatesType::UnsupportedType,
96
97
  "Unsupported type #{ symbol.to_s.camelize } given for validates_type.")
97
98
  end
@@ -119,6 +120,7 @@ module ActiveModel
119
120
  # - :symbol
120
121
  # - :time
121
122
  # - :date
123
+ # - :big_decimal
122
124
  #
123
125
  # class Foo
124
126
  # include ActiveModel::Validations
@@ -240,6 +240,32 @@ describe 'ValidatesType' do
240
240
  end
241
241
  end
242
242
 
243
+ describe 'BigDecimal' do
244
+
245
+ subject { ActiveModel::TypeValidationTestClass.set_accessor_and_long_validator(:big_decimal) }
246
+
247
+ context 'field value is a BigDecimal' do
248
+ let(:value) { BigDecimal.new(1) }
249
+
250
+ specify do
251
+ expect(subject).to be_valid
252
+ end
253
+ end
254
+
255
+ context 'field value is not a BigDecimal' do
256
+ let(:value) { 123456 }
257
+ specify do
258
+ expect(subject).to_not be_valid
259
+ end
260
+
261
+ specify do
262
+ subject.validate
263
+ expect(subject.errors).to_not be_empty
264
+ expect(subject.errors.messages[:attribute][0]).to match(/is expected to be a BigDecimal and is not/)
265
+ end
266
+ end
267
+ end
268
+
243
269
  context 'passing in a custom message' do
244
270
  subject { ActiveModel::TypeValidationTestClass.set_accessor_and_long_validator(:string, message: 'is not a String!') }
245
271
 
@@ -344,6 +344,33 @@ describe 'ValidatesType' do
344
344
  end
345
345
  end
346
346
  end
347
+
348
+ describe 'BigDecimal' do
349
+ drop_and_create_column_with_type(:string)
350
+
351
+ subject { TypeValidationTest.set_accessor_and_long_validator(:big_decimal) }
352
+
353
+ context 'field value is a BigDecimal' do
354
+ let(:value) { BigDecimal.new(1) }
355
+
356
+ specify do
357
+ expect(subject).to be_valid
358
+ end
359
+ end
360
+
361
+ context 'field value is not a BigDecimal' do
362
+ let(:value) { 123456 }
363
+ specify do
364
+ expect(subject).to_not be_valid
365
+ end
366
+
367
+ specify do
368
+ subject.validate
369
+ expect(subject.errors).to_not be_empty
370
+ expect(subject.errors.messages[:test_attribute][0]).to match(/is expected to be a BigDecimal and is not/)
371
+ end
372
+ end
373
+ end
347
374
  end
348
375
 
349
376
  context 'unsupported types' do
data/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ValidatesType
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_type
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Yesbeck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-18 00:00:00.000000000 Z
11
+ date: 2015-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-boolean