compendium 1.1.3.2 → 1.1.3.3

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTRmYjc0MzRiODE5OWFjNGJmM2M4MWEzOTBkNTFkZTNhYWE3N2NjYw==
4
+ YThkODFkMDI0MDhhNjY4MzE4MWVhODA4ZTkxOGQ3MDg2YzM4YmQzYQ==
5
5
  data.tar.gz: !binary |-
6
- NGJjNTc5NjFkMjhmNTIyZTgxYjkwYTY1ZTM1NjQzZTI5MTkyYTUzYw==
6
+ N2M4NGEyMWUyZTA4MmM1NmMxZTQ5N2JlMTk4NDg3NDVmZTc4ZjM2OA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZmEyZmZmOTEwYTBhODAwYTczODRmOTYxYmUwZjMxNDFmNGU5N2YyZmVmOGFi
10
- MzE4NWVjZGFjOGQwOWNkMDlkZTVjY2VlZTYzMjM4ZDc1ZWUzMDA4YzVmZWQ4
11
- M2JjYzg0MGFiN2RhOWQwOGUxODUwNjI0OTdlOWVmZjFhZGIxODM=
9
+ MTFmMTE3YWFlMGI4YjM1YTY5MzQ1ODY0NWJkNThkMGZjMTQ0MGMwYjY5NzM1
10
+ MDc0OWU2MDlmZGE5YzNlOTNhYjJiMDk2ZTY3NjA5Njc2NjU0YmRhNjE4OGE3
11
+ MjBjNGJmMmViOTI5MTVlODI5N2YyZTM1NTFkNGJiNjIwYzRhN2U=
12
12
  data.tar.gz: !binary |-
13
- NjI2OWI0NDc1N2I4ODdiMzdhNWQwYTQ1MGJiMTlkNGE1ZmY5NWY2YmZhZmM1
14
- Y2RhMGVmZDhlZDI0MTI0Yjg3MmNjNjY1MmFmNmUyYjcyMWVmMTVkYTc3OTlh
15
- NjcxYjc4MmVmYjNiMzJlOTc3MjU0ZWZmMDllMjRjZDAwMTk5NGI=
13
+ ZDdjZmJiNDJhNDllZjQxMzc0YWQ4MWQ2NTY1NzBkOGVmY2M3ZmViOWZhZjM0
14
+ YmIxYzk0NzQ1NjAyNThjZDFjMzAyNzcxMTQyYzM3MzhkOGRkN2VhYWFlMDdh
15
+ YjlkMGRlZjNjODkzYTAwYmYwMTcwNGJiODQ1ZWNhNmYwYjZlZjc=
@@ -19,6 +19,14 @@ module Compendium
19
19
  def nil?
20
20
  __getobj__.nil?
21
21
  end
22
+
23
+ def to_f
24
+ Kernel.Float(__getobj__)
25
+ end
26
+
27
+ def to_i
28
+ Kernel.Integer(__getobj__)
29
+ end
22
30
  end
23
31
 
24
32
  class ParamWithChoices < Param
@@ -14,6 +14,8 @@ module Compendium
14
14
  delegate :report_name, :url, to: 'self.class'
15
15
 
16
16
  class << self
17
+ delegate :validate, to: :params_class
18
+
17
19
  def inherited(report)
18
20
  Compendium.reports << report
19
21
 
@@ -1,3 +1,3 @@
1
1
  module Compendium
2
- VERSION = "1.1.3.2"
2
+ VERSION = "1.1.3.3"
3
3
  end
data/spec/params_spec.rb CHANGED
@@ -8,6 +8,7 @@ describe Compendium::Params do
8
8
  opts << Compendium::Option.new(name: :report_type, type: :radio, choices: [:big, :small])
9
9
  opts << Compendium::Option.new(name: :boolean, type: :boolean)
10
10
  opts << Compendium::Option.new(name: :another_boolean, type: :boolean)
11
+ opts << Compendium::Option.new(name: :number, type: :scalar)
11
12
  opts
12
13
  }
13
14
 
@@ -30,14 +31,28 @@ describe Compendium::Params do
30
31
 
31
32
  describe "#validations" do
32
33
  let(:report_class) { Class.new(described_class) }
33
- subject { report_class.new({}, options) }
34
34
 
35
- before do
36
- report_class.validates :ending_on, presence: true
37
- subject.valid?
35
+ context 'presence' do
36
+ subject { report_class.new({}, options) }
37
+
38
+ before do
39
+ report_class.validates :ending_on, presence: true
40
+ subject.valid?
41
+ end
42
+
43
+ it { should_not be_valid }
44
+ its('errors.keys') { should include :ending_on }
38
45
  end
39
46
 
40
- it { should_not be_valid }
41
- its('errors.keys') { should include :ending_on }
47
+ context 'numericality' do
48
+ subject { report_class.new({ number: 'abcd' }, options) }
49
+ before do
50
+ report_class.validates :number, numericality: true
51
+ subject.valid?
52
+ end
53
+
54
+ it { should_not be_valid }
55
+ its('errors.keys') { should include :number }
56
+ end
42
57
  end
43
58
  end
data/spec/report_spec.rb CHANGED
@@ -222,20 +222,46 @@ describe Compendium::Report do
222
222
  end
223
223
 
224
224
  describe "#valid?" do
225
- let(:report_class) do
226
- Class.new(described_class) do
227
- option :id, :dropdown, choices: (0..10).to_a, validates: { presence: true }
225
+ context 'built-in validations' do
226
+ let(:report_class) do
227
+ Class.new(described_class) do
228
+ option :id, :dropdown, choices: (0..10).to_a, validates: { presence: true }
229
+ end
228
230
  end
229
- end
230
231
 
231
- it "should return true if there are no validation failures" do
232
- r = report_class.new(id: 5)
233
- r.should be_valid
232
+ it "should return true if there are no validation failures" do
233
+ r = report_class.new(id: 5)
234
+ r.should be_valid
235
+ end
236
+
237
+ it "should return false if there are validation failures" do
238
+ r = report_class.new(id: nil)
239
+ r.should_not be_valid
240
+ r.errors.keys.should include :id
241
+ end
234
242
  end
235
243
 
236
- it "should return false if there are validation failures" do
237
- r = report_class.new(id: nil)
238
- r.should_not be_valid
244
+ context 'custom validation' do
245
+ let(:report_class) do
246
+ Class.new(described_class) do
247
+ option :number, :scalar
248
+
249
+ validate do
250
+ errors.add(:number, :invalid_number) unless number.even?
251
+ end
252
+ end
253
+ end
254
+
255
+ it "should return true if there are no validation failures" do
256
+ r = report_class.new(number: 4)
257
+ r.should be_valid
258
+ end
259
+
260
+ it "should return false if there are validation failures" do
261
+ r = report_class.new(number: 5)
262
+ r.should_not be_valid
263
+ r.errors.keys.should include :number
264
+ end
239
265
  end
240
266
  end
241
267
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compendium
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3.2
4
+ version: 1.1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Vandersluis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-12 00:00:00.000000000 Z
11
+ date: 2015-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  type: :runtime