id 0.0.12 → 0.1
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 +4 -4
- data/Gemfile +0 -3
- data/Gemfile.lock +25 -10
- data/LICENSE.md +1 -1
- data/README.md +173 -35
- data/id.gemspec +8 -3
- data/lib/id.rb +21 -15
- data/lib/id/active_model.rb +30 -0
- data/lib/id/association.rb +26 -0
- data/lib/id/boolean.rb +8 -0
- data/lib/id/coercion.rb +38 -0
- data/lib/id/eta_expansion.rb +5 -0
- data/lib/id/field.rb +46 -0
- data/lib/id/field/definition.rb +44 -0
- data/lib/id/field/summary.rb +35 -0
- data/lib/id/form.rb +41 -13
- data/lib/id/form_backwards_compatibility.rb +6 -0
- data/lib/id/hashifier.rb +13 -24
- data/lib/id/model.rb +29 -25
- data/lib/id/timestamps.rb +15 -15
- data/lib/id/validations.rb +8 -0
- data/spec/examples/cat_spec.rb +37 -0
- data/spec/lib/id/active_model_spec.rb +40 -0
- data/spec/lib/id/association_spec.rb +73 -0
- data/spec/lib/id/boolean_spec.rb +38 -0
- data/spec/lib/id/coercion_spec.rb +53 -0
- data/spec/lib/id/eta_expansion_spec.rb +13 -0
- data/spec/lib/id/field/definition_spec.rb +37 -0
- data/spec/lib/id/field/summary_spec.rb +26 -0
- data/spec/lib/id/field_spec.rb +62 -0
- data/spec/lib/id/form_spec.rb +84 -0
- data/spec/lib/id/hashifier_spec.rb +19 -0
- data/spec/lib/id/model_spec.rb +30 -180
- data/spec/lib/id/timestamps_spec.rb +22 -20
- data/spec/lib/id/validations_spec.rb +18 -0
- data/spec/spec_helper.rb +11 -5
- data/spec/support/dummy_rails_form_builder.rb +9 -0
- metadata +84 -26
- data/lib/id/form/active_model_form.rb +0 -41
- data/lib/id/form/descriptor.rb +0 -27
- data/lib/id/form/field_form.rb +0 -14
- data/lib/id/form/field_with_form_support.rb +0 -12
- data/lib/id/missing_attribute_error.rb +0 -4
- data/lib/id/model/association.rb +0 -49
- data/lib/id/model/definer.rb +0 -23
- data/lib/id/model/descriptor.rb +0 -23
- data/lib/id/model/field.rb +0 -61
- data/lib/id/model/has_many.rb +0 -11
- data/lib/id/model/has_one.rb +0 -17
- data/lib/id/model/type_casts.rb +0 -96
- data/spec/lib/id/model/association_spec.rb +0 -27
- data/spec/lib/id/model/field_spec.rb +0 -0
- data/spec/lib/id/model/form_spec.rb +0 -56
- data/spec/lib/id/model/type_casts_spec.rb +0 -44
- data/spec/lib/mike_spec.rb +0 -20
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Id
|
4
|
-
module Model
|
5
|
-
module TypeCasts
|
6
|
-
|
7
|
-
describe Cast do
|
8
|
-
it 'requires a type' do
|
9
|
-
expect { Cast.new(1).type }.to raise_error NotImplementedError
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'requires a conversion' do
|
13
|
-
expect { Cast.new(1).conversion }.to raise_error NotImplementedError
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
describe Date do
|
19
|
-
it 'casts strings to dates' do
|
20
|
-
Date.new("06-06-1983").cast.should eq ::Date.new(1983, 6, 6)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe Time do
|
25
|
-
it 'casts strings to Times' do
|
26
|
-
Time.new("06-06-1983").cast.should eq ::Time.parse("06-06-1983")
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'does nothing if the value is already of the correct type' do
|
30
|
-
time = ::Time.now
|
31
|
-
Time.new(time).cast.should eq time
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe Money do
|
36
|
-
it 'ints or strings to Money' do
|
37
|
-
Money.new("500").cast.should eq ::Money.new(5_00)
|
38
|
-
Money.new(500).cast.should eq ::Money.new(5_00)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
data/spec/lib/mike_spec.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
class Mike
|
4
|
-
include Id::Model
|
5
|
-
|
6
|
-
field :cat
|
7
|
-
field :dog, :optional => true
|
8
|
-
|
9
|
-
def catdog
|
10
|
-
dog.value_or cat
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "Foobar" do
|
16
|
-
let (:mike) { Mike.new(:cat => 'pooface') }
|
17
|
-
it 'returns cat' do
|
18
|
-
mike.catdog.should eq 'pooface'
|
19
|
-
end
|
20
|
-
end
|