hashme 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,12 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  describe Hashme::Property do
4
4
 
5
- let :owner do
6
- double()
5
+ subject do
6
+ described_class
7
7
  end
8
8
 
9
- let :klass do
10
- Hashme::Property
9
+ let :owner do
10
+ double()
11
11
  end
12
12
 
13
13
  let :submodel do
@@ -18,72 +18,70 @@ describe Hashme::Property do
18
18
  end
19
19
 
20
20
  describe "#initialize" do
21
-
22
21
  it "should copy name and type" do
23
- prop = klass.new("name", String)
24
- prop.name.should eql(:name)
25
- prop.type.should eql(String)
26
- prop.use_casted_array?.should be_false
22
+ prop = subject.new("name", String)
23
+ expect(prop.name).to eql(:name)
24
+ expect(prop.type).to eql(String)
25
+ expect(prop.array).to be_falsey
27
26
  end
28
27
 
29
28
  it "should convert Array to CastedArray type" do
30
- prop = klass.new("names", [String])
31
- prop.name.should eql(:names)
32
- prop.type.should eql(String)
33
- prop.use_casted_array?.should be_true
29
+ prop = subject.new("names", [String])
30
+ expect(prop.name).to eql(:names)
31
+ expect(prop.type).to eql(String)
32
+ expect(prop.array).to be_truthy
34
33
  end
35
34
 
36
35
  it "should accept a default option" do
37
- prop = klass.new(:name, String, :default => "Freddo")
38
- prop.default.should eql("Freddo")
36
+ prop = subject.new(:name, String, :default => "Freddo")
37
+ expect(prop.default).to eql("Freddo")
39
38
  end
40
-
41
39
  end
42
40
 
43
41
  describe "#to_s" do
44
42
  it "should use property's name" do
45
- prop = klass.new(:name, String)
46
- prop.to_s.should eql("name")
43
+ prop = subject.new(:name, String)
44
+ expect(prop.to_s).to eql("name")
47
45
  end
48
46
  end
49
47
 
50
48
  describe "#to_sym" do
51
49
  it "should return the name" do
52
- prop = klass.new(:name, String)
53
- prop.to_sym.should eql (:name)
50
+ prop = subject.new(:name, String)
51
+ expect(prop.to_sym).to eql (:name)
54
52
  end
55
53
  end
56
54
 
57
- describe "#cast" do
55
+ describe "#build" do
58
56
  context "without an array" do
59
57
  it "should build a new object" do
60
- prop = klass.new(:date, Time)
61
- obj = prop.cast(owner, "2013-06-02T12:00:00")
62
- obj.class.should eql(Time)
63
- obj.should eql(Time.new("2013-06-02T12:00:00"))
58
+ prop = subject.new(:date, Time)
59
+ obj = prop.build(owner, "2013-06-02T12:00:00Z")
60
+ expect(obj.class).to eql(Time)
61
+ expect(obj).to eql(Time.utc(2013, 6, 2, 12, 0, 0))
64
62
  end
65
63
 
66
64
  it "should assign casted by and property" do
67
- prop = klass.new(:item, submodel)
68
- obj = prop.cast(owner, {:name => 'test'})
69
- obj.casted_by.should eql(owner)
70
- obj.casted_by_property.should eql(prop)
65
+ prop = subject.new(:item, submodel)
66
+ obj = prop.build(owner, {:name => 'test'})
67
+ expect(obj.casted_by).to eql(owner)
68
+ expect(obj.casted_by_property).to eql(prop)
71
69
  end
72
70
  end
73
71
 
74
72
  context "with an array" do
75
73
  it "should convert regular array to casted array" do
76
- prop = klass.new(:dates, [Time])
77
- obj = prop.cast(owner, ["2013-06-02T12:00:00"])
78
- obj.class.should eql(Hashme::CastedArray)
79
- obj.first.class.should eql(Time)
74
+ prop = subject.new(:dates, [Time])
75
+ obj = prop.build(owner, ["2013-06-02T12:00:00"])
76
+ expect(obj.class).to eql(Hashme::CastedArray)
77
+ expect(obj.first.class).to eql(Time)
80
78
  end
81
79
  it "should handle complex objects" do
82
- prop = klass.new(:items, [submodel])
83
- obj = prop.cast(owner, [{:name => 'test'}])
84
- obj.class.should eql(Hashme::CastedArray)
85
- obj.first.class.should eql(submodel)
86
- obj.first.name.should eql('test')
80
+ prop = subject.new(:items, [submodel])
81
+ obj = prop.build(owner, [{:name => 'test'}])
82
+ expect(obj.class).to eql(Hashme::CastedArray)
83
+ expect(obj.first.class).to eql(submodel)
84
+ expect(obj.first.name).to eql('test')
87
85
  end
88
86
  end
89
87
  end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Lown
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-10 00:00:00.000000000 Z
11
+ date: 2016-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: Modeling with Hashes made easy.
@@ -73,7 +73,8 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - .gitignore
76
+ - ".gitignore"
77
+ - ".rspec"
77
78
  - Gemfile
78
79
  - LICENSE.txt
79
80
  - README.md
@@ -85,11 +86,13 @@ files:
85
86
  - lib/hashme/casted_array.rb
86
87
  - lib/hashme/properties.rb
87
88
  - lib/hashme/property.rb
89
+ - lib/hashme/property_casting.rb
88
90
  - lib/hashme/version.rb
89
91
  - spec/hashme/attributes_spec.rb
90
92
  - spec/hashme/base_spec.rb
91
93
  - spec/hashme/casted_array_spec.rb
92
94
  - spec/hashme/properties_spec.rb
95
+ - spec/hashme/property_casting_spec.rb
93
96
  - spec/hashme/property_spec.rb
94
97
  - spec/spec_helper.rb
95
98
  homepage: ''
@@ -102,17 +105,17 @@ require_paths:
102
105
  - lib
103
106
  required_ruby_version: !ruby/object:Gem::Requirement
104
107
  requirements:
105
- - - '>='
108
+ - - ">="
106
109
  - !ruby/object:Gem::Version
107
110
  version: '0'
108
111
  required_rubygems_version: !ruby/object:Gem::Requirement
109
112
  requirements:
110
- - - '>='
113
+ - - ">="
111
114
  - !ruby/object:Gem::Version
112
115
  version: '0'
113
116
  requirements: []
114
117
  rubyforge_project:
115
- rubygems_version: 2.0.5
118
+ rubygems_version: 2.4.6
116
119
  signing_key:
117
120
  specification_version: 4
118
121
  summary: Easily define simple models that can be easily serialized and de-serialized.
@@ -121,5 +124,6 @@ test_files:
121
124
  - spec/hashme/base_spec.rb
122
125
  - spec/hashme/casted_array_spec.rb
123
126
  - spec/hashme/properties_spec.rb
127
+ - spec/hashme/property_casting_spec.rb
124
128
  - spec/hashme/property_spec.rb
125
129
  - spec/spec_helper.rb