dm-types 0.9.11 → 0.10.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.
Files changed (59) hide show
  1. data/{History.txt → History.rdoc} +5 -4
  2. data/LICENSE +16 -14
  3. data/Manifest.txt +13 -3
  4. data/{README.txt → README.rdoc} +0 -0
  5. data/Rakefile +3 -4
  6. data/TODO +74 -0
  7. data/lib/dm-types.rb +15 -18
  8. data/lib/dm-types/bcrypt_hash.rb +1 -4
  9. data/lib/dm-types/comma_separated_list.rb +31 -0
  10. data/lib/dm-types/csv.rb +12 -18
  11. data/lib/dm-types/enum.rb +18 -15
  12. data/lib/dm-types/epoch_time.rb +6 -11
  13. data/lib/dm-types/file_path.rb +5 -4
  14. data/lib/dm-types/flag.rb +14 -13
  15. data/lib/dm-types/ip_address.rb +1 -0
  16. data/lib/dm-types/json.rb +5 -11
  17. data/lib/dm-types/regexp.rb +2 -3
  18. data/lib/dm-types/slug.rb +8 -17
  19. data/lib/dm-types/uri.rb +8 -14
  20. data/lib/dm-types/uuid.rb +9 -15
  21. data/lib/dm-types/version.rb +1 -1
  22. data/lib/dm-types/yaml.rb +4 -3
  23. data/spec/fixtures/article.rb +39 -0
  24. data/spec/fixtures/bookmark.rb +27 -0
  25. data/spec/fixtures/invention.rb +9 -0
  26. data/spec/fixtures/network_node.rb +40 -0
  27. data/spec/fixtures/person.rb +29 -0
  28. data/spec/fixtures/software_package.rb +37 -0
  29. data/spec/fixtures/ticket.rb +25 -0
  30. data/spec/fixtures/tshirt.rb +28 -0
  31. data/spec/integration/bcrypt_hash_spec.rb +37 -55
  32. data/spec/integration/comma_separated_list_spec.rb +89 -0
  33. data/spec/integration/enum_spec.rb +62 -42
  34. data/spec/integration/file_path_spec.rb +149 -17
  35. data/spec/integration/flag_spec.rb +56 -25
  36. data/spec/integration/ip_address_spec.rb +142 -17
  37. data/spec/integration/json_spec.rb +60 -17
  38. data/spec/integration/slug_spec.rb +39 -40
  39. data/spec/integration/uri_spec.rb +126 -21
  40. data/spec/integration/uuid_spec.rb +84 -30
  41. data/spec/integration/yaml_spec.rb +55 -25
  42. data/spec/shared/identity_function_group.rb +5 -0
  43. data/spec/spec.opts +1 -0
  44. data/spec/spec_helper.rb +49 -17
  45. data/spec/unit/bcrypt_hash_spec.rb +107 -64
  46. data/spec/unit/csv_spec.rb +111 -27
  47. data/spec/unit/enum_spec.rb +128 -87
  48. data/spec/unit/epoch_time_spec.rb +57 -32
  49. data/spec/unit/file_path_spec.rb +55 -34
  50. data/spec/unit/flag_spec.rb +102 -65
  51. data/spec/unit/ip_address_spec.rb +90 -40
  52. data/spec/unit/json_spec.rb +108 -41
  53. data/spec/unit/regexp_spec.rb +47 -17
  54. data/spec/unit/uri_spec.rb +57 -46
  55. data/spec/unit/yaml_spec.rb +91 -45
  56. data/tasks/install.rb +1 -1
  57. data/tasks/spec.rb +4 -4
  58. metadata +25 -32
  59. data/lib/dm-types/serial.rb +0 -8
@@ -1,49 +1,70 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname.parent.expand_path + 'spec_helper'
1
+ require 'spec_helper'
3
2
 
4
- describe DataMapper::Types::FilePath do
3
+ try_spec do
4
+ describe DataMapper::Types::FilePath do
5
+ before do
6
+ @input = '/usr/bin/ruby'
7
+ @path = Pathname.new(@input)
8
+ end
5
9
 
6
- before(:each) do
7
- @path_str = "/usr/bin/ruby"
8
- @path = Pathname.new(@path_str)
9
- end
10
+ describe '.dump' do
11
+ describe 'when input is a string' do
12
+ it 'does not modify input' do
13
+ DataMapper::Types::FilePath.dump(@input, :property).should == @input
14
+ end
15
+ end
10
16
 
11
- describe ".dump" do
12
- it "should return the file path as a String" do
13
- DataMapper::Types::FilePath.dump(@path_str, :property).should == @path_str
14
- end
17
+ describe 'when input is nil' do
18
+ it 'returns nil' do
19
+ DataMapper::Types::FilePath.dump(nil, :property).should be_nil
20
+ end
21
+ end
15
22
 
16
- it "should return nil if the String is nil" do
17
- DataMapper::Types::FilePath.dump(nil, :property).should be_nil
23
+ describe 'when input is a blank string' do
24
+ it 'returns nil' do
25
+ DataMapper::Types::FilePath.dump('', :property).should be_nil
26
+ end
27
+ end
18
28
  end
19
29
 
20
- it "should return an empty file path if the String is empty" do
21
- DataMapper::Types::FilePath.dump("", :property).should == ""
22
- end
23
- end
30
+ describe '.load' do
31
+ describe 'when value is a non-blank file path' do
32
+ it 'returns Pathname for a path' do
33
+ DataMapper::Types::FilePath.load(@input, :property).should == @path
34
+ end
35
+ end
24
36
 
25
- describe ".load" do
26
- it "should return the file path as a Pathname" do
27
- DataMapper::Types::FilePath.load(@uri_str, :property).should == @uri
28
- end
37
+ describe 'when value is nil' do
38
+ it 'return nil' do
39
+ DataMapper::Types::FilePath.load(nil, :property).should be_nil
40
+ end
41
+ end
29
42
 
30
- it "should return nil if given nil" do
31
- DataMapper::Types::FilePath.load(nil, :property).should be_nil
43
+ describe 'when value is a blank string' do
44
+ it 'returns nil' do
45
+ DataMapper::Types::FilePath.load('', :property).should be_nil
46
+ end
47
+ end
32
48
  end
33
49
 
34
- it "should return an empty Pathname if given an empty String" do
35
- DataMapper::Types::FilePath.load("", :property).should == Pathname.new("")
36
- end
37
- end
50
+ describe '.typecast' do
51
+ describe 'when a Pathname is given' do
52
+ it 'does not modify input' do
53
+ DataMapper::Types::FilePath.typecast(@path, :property).should == @path
54
+ end
55
+ end
38
56
 
39
- describe '.typecast' do
40
- it 'should do nothing if a Pathname is provided' do
41
- DataMapper::Types::FilePath.typecast(@path, :property).should == @path
42
- end
57
+ describe 'when a nil is given' do
58
+ it 'does not modify input' do
59
+ DataMapper::Types::FilePath.typecast(nil, :property).should == nil
60
+ end
61
+ end
43
62
 
44
- it 'should defer to .load if a string is provided' do
45
- DataMapper::Types::FilePath.should_receive(:load).with(@path_str, :property)
46
- DataMapper::Types::FilePath.typecast(@path_str, :property)
63
+ describe 'when a string is given' do
64
+ it 'returns Pathname for given path' do
65
+ DataMapper::Types::FilePath.typecast(@input, :property).should == @path
66
+ end
67
+ end
47
68
  end
48
69
  end
49
70
  end
@@ -1,86 +1,123 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname.parent.expand_path + 'spec_helper'
1
+ require 'spec_helper'
3
2
 
4
- describe DataMapper::Types::Flag do
5
-
6
- describe ".new" do
7
- it "should create a Class" do
8
- DataMapper::Types::Flag.new.should be_instance_of(Class)
9
- end
10
-
11
- it "should create unique a Class each call" do
12
- DataMapper::Types::Flag.new.should_not == DataMapper::Types::Flag.new
13
- end
3
+ describe 'factory method for Flag type', :shared => true do
4
+ it 'creates a Class' do
5
+ DataMapper::Types::Flag.new.should be_instance_of(Class)
6
+ end
14
7
 
15
- it "should use the arguments as the values in the @flag_map hash" do
16
- DataMapper::Types::Flag.new(:first, :second, :third).flag_map.values.should == [:first, :second, :third]
17
- end
8
+ it 'creates unique a Class each call' do
9
+ DataMapper::Types::Flag.new.should_not == DataMapper::Types::Flag.new
10
+ end
18
11
 
19
- it "should create keys by the 2 power series for the @flag_map hash, staring at 1" do
20
- DataMapper::Types::Flag.new(:one, :two, :three, :four, :five).flag_map.keys.should include(1, 2, 4, 8, 16)
21
- end
12
+ it 'builds up flags map from arguments' do
13
+ DataMapper::Types::Flag.new(:first, :second, :third).flag_map.values.should == [ :first, :second, :third ]
22
14
  end
23
15
 
24
- describe ".[]" do
25
- it "should be an alias for the new method" do
26
- DataMapper::Types::Flag.should_receive(:new).with(:uno, :dos, :tres)
27
- DataMapper::Types::Flag[:uno, :dos, :tres]
28
- end
16
+ it 'should create keys that is +1 for every increment for the @flag_map hash, staring at 0' do
17
+ DataMapper::Types::Flag.new(:one, :two, :three, :four, :five).flag_map.keys.should include(0, 1, 2, 3, 4)
29
18
  end
19
+ end
30
20
 
31
- describe ".dump" do
32
- before(:each) do
33
- @flag = DataMapper::Types::Flag[:first, :second, :third, :fourth, :fifth]
21
+ try_spec do
22
+ describe DataMapper::Types::Flag do
23
+ describe '.new' do
24
+ it_should_behave_like 'factory method for Flag type'
34
25
  end
35
26
 
36
- it "should return the key of the value match from the flag map" do
37
- @flag.dump(:first, :property).should == 1
38
- @flag.dump(:second, :property).should == 2
39
- @flag.dump(:third, :property).should == 4
40
- @flag.dump(:fourth, :property).should == 8
41
- @flag.dump(:fifth, :property).should == 16
27
+ describe '.[]' do
28
+ it_should_behave_like 'factory method for Flag type'
42
29
  end
43
30
 
44
- it "should return a binary flag built from the key values of all matches" do
45
- @flag.dump([:first, :second], :property).should == 3
46
- @flag.dump([:second, :fourth], :property).should == 10
47
- @flag.dump([:first, :second, :third, :fourth, :fifth], :property).should == 31
48
- end
31
+ describe '.dump' do
32
+ before :all do
33
+ @flag = DataMapper::Types::Flag[:first, :second, :third, :fourth, :fifth]
34
+ end
49
35
 
50
- it "should return a binary flag built from the key values of all matches even if strings" do
51
- @flag.dump(["first", "second"], :property).should == 3
52
- @flag.dump(["second", "fourth"], :property).should == 10
53
- @flag.dump(["first", "second", "third", "fourth", "fifth"], :property).should == 31
54
- end
36
+ describe 'when argument matches a value in the flag map' do
37
+ before :all do
38
+ @result = @flag.dump(:first, :property)
39
+ end
55
40
 
56
- it "should return 0 if there is no match" do
57
- @flag.dump(:zero, :property).should == 0
58
- end
59
- end
41
+ it 'returns flag bit of value' do
42
+ @result.should == 1
43
+ end
44
+ end
60
45
 
61
- describe ".load" do
62
- before(:each) do
63
- @flag = DataMapper::Types::Flag[:uno, :dos, :tres, :cuatro, :cinco]
64
- end
46
+ describe 'when argument matches 2nd value in the flag map' do
47
+ before :all do
48
+ @result = @flag.dump(:second, :property)
49
+ end
65
50
 
66
- it "should return the value of the key match from the flag map" do
67
- @flag.load(1, :property).should == [:uno]
68
- @flag.load(2, :property).should == [:dos]
69
- @flag.load(4, :property).should == [:tres]
70
- @flag.load(8, :property).should == [:cuatro]
71
- @flag.load(16, :property).should == [:cinco]
72
- end
51
+ it 'returns flag bit of value' do
52
+ @result.should == 2
53
+ end
54
+ end
55
+
56
+ describe 'when argument matches multiple Symbol values in the flag map' do
57
+ before :all do
58
+ @result = @flag.dump([ :second, :fourth ], :property)
59
+ end
60
+
61
+ it 'builds binary flag from key values of all matches' do
62
+ @result.should == 10
63
+ end
64
+ end
65
+
66
+ describe 'when argument matches multiple string values in the flag map' do
67
+ before :all do
68
+ @result = @flag.dump(['first', 'second', 'third', 'fourth', 'fifth'], :property)
69
+ end
70
+
71
+ it 'builds binary flag from key values of all matches' do
72
+ @result.should == 31
73
+ end
74
+ end
75
+
76
+ describe 'when argument does not match a single value in the flag map' do
77
+ before :all do
78
+ @result = @flag.dump(:zero, :property)
79
+ end
73
80
 
74
- it "should return an array of all flags matches" do
75
- @flag.load(3, :property).should include(:uno, :dos)
76
- @flag.load(10, :property).should include(:dos, :cuatro)
77
- @flag.load(31, :property).should include(:uno, :dos, :tres, :cuatro, :cinco)
81
+ it 'returns zero' do
82
+ @result.should == 0
83
+ end
84
+ end
78
85
  end
79
86
 
80
- it "should return an empty array if there is no key" do
81
- @flag.load(-1, :property).should == []
82
- @flag.load(nil, :property).should == []
83
- @flag.load(32, :property).should == []
87
+ describe '.load' do
88
+ before :all do
89
+ @flag = DataMapper::Types::Flag[:uno, :dos, :tres, :cuatro, :cinco]
90
+ end
91
+
92
+ describe 'when argument matches a key in the flag map' do
93
+ before :all do
94
+ @result = @flag.load(4, :property)
95
+ end
96
+
97
+ it 'returns array with a single matching element' do
98
+ @result.should == [ :tres ]
99
+ end
100
+ end
101
+
102
+ describe 'when argument matches multiple keys in the flag map' do
103
+ before :all do
104
+ @result = @flag.load(10, :property)
105
+ end
106
+
107
+ it 'returns array of matching values' do
108
+ @result.should == [ :dos, :cuatro ]
109
+ end
110
+ end
111
+
112
+ describe 'when argument does not match a single key in the flag map' do
113
+ before :all do
114
+ @result = @flag.load(nil, :property)
115
+ end
116
+
117
+ it 'returns an empty array' do
118
+ @result.should == []
119
+ end
120
+ end
84
121
  end
85
122
  end
86
123
  end
@@ -1,56 +1,106 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname.parent.expand_path + 'spec_helper'
1
+ require 'spec_helper'
3
2
 
4
- describe DataMapper::Types::IPAddress do
3
+ try_spec do
4
+ describe DataMapper::Types::IPAddress do
5
+ before :all do
6
+ @stored = '81.20.130.1'
7
+ @input = IPAddr.new(@stored)
8
+ end
5
9
 
6
- before(:each) do
7
- @ip_str = "81.20.130.1"
8
- @ip = IPAddr.new(@ip_str)
9
- end
10
+ describe '.dump' do
11
+ describe 'when argument is an IP address given as Ruby object' do
12
+ before :all do
13
+ @result = DataMapper::Types::IPAddress.dump(@input, :property)
14
+ end
10
15
 
11
- describe ".dump" do
12
- it "should return the IP address as a string" do
13
- DataMapper::Types::IPAddress.dump(@ip, :property).should == @ip_str
14
- end
16
+ it 'dumps input into a string' do
17
+ @result.should == @stored
18
+ end
19
+ end
15
20
 
16
- it "should return nil if the string is nil" do
17
- DataMapper::Types::IPAddress.dump(nil, :property).should be_nil
18
- end
21
+ describe 'when argument is nil' do
22
+ before :all do
23
+ @result = DataMapper::Types::IPAddress.dump(nil, :property)
24
+ end
19
25
 
20
- it "should return an empty IP address if the string is empty" do
21
- DataMapper::Types::IPAddress.dump("", :property).should == ""
22
- end
23
- end
26
+ it 'returns nil' do
27
+ @result.should be_nil
28
+ end
29
+ end
24
30
 
25
- describe ".load" do
26
- it "should return the IP address string as IPAddr" do
27
- DataMapper::Types::IPAddress.load(@ip_str, :property).should == @ip
28
- end
31
+ describe 'when input is a blank string' do
32
+ before :all do
33
+ @result = DataMapper::Types::IPAddress.dump('', :property)
34
+ end
29
35
 
30
- it "should return nil if given nil" do
31
- DataMapper::Types::IPAddress.load(nil, :property).should be_nil
36
+ it 'retuns a blank string' do
37
+ @result.should == ''
38
+ end
39
+ end
32
40
  end
33
41
 
34
- it "should return an empty IP address if given an empty string" do
35
- DataMapper::Types::IPAddress.load("", :property).should == IPAddr.new("0.0.0.0")
36
- end
42
+ describe '.load' do
43
+ describe 'when argument is a valid IP address as a string' do
44
+ before :all do
45
+ @result = DataMapper::Types::IPAddress.load(@stored, :property)
46
+ end
37
47
 
38
- it 'should raise an ArgumentError if given something else' do
39
- lambda {
40
- DataMapper::Types::IPAddress.load([], :property)
41
- }.should raise_error(ArgumentError, '+value+ must be nil or a String')
42
- end
43
- end
48
+ it 'returns IPAddr instance from stored value' do
49
+ @result.should == @input
50
+ end
51
+ end
44
52
 
45
- describe '.typecast' do
46
- it 'should do nothing if an IpAddr is provided' do
47
- DataMapper::Types::IPAddress.typecast(@ip, :property).should == @ip
53
+ describe 'when argument is nil' do
54
+ before :all do
55
+ @result = DataMapper::Types::IPAddress.load(nil, :property)
56
+ end
57
+
58
+ it 'returns nil' do
59
+ @result.should be_nil
60
+ end
61
+ end
62
+
63
+ describe 'when argument is a blank string' do
64
+ before :all do
65
+ @result = DataMapper::Types::IPAddress.load('', :property)
66
+ end
67
+
68
+ it 'returns IPAddr instance from stored value' do
69
+ @result.should == IPAddr.new('0.0.0.0')
70
+ end
71
+ end
72
+
73
+ describe 'when argument is an Array instance' do
74
+ before :all do
75
+ @operation = lambda { DataMapper::Types::IPAddress.load([], :property) }
76
+ end
77
+
78
+ it 'raises ArgumentError with a meaningful message' do
79
+ @operation.should raise_error(ArgumentError, '+value+ must be nil or a String')
80
+ end
81
+ end
48
82
  end
49
83
 
50
- it 'should defer to .load if a string is provided' do
51
- DataMapper::Types::IPAddress.should_receive(:load).with(@ip_str, :property)
52
- DataMapper::Types::IPAddress.typecast(@ip_str, :property)
84
+ describe '.typecast' do
85
+ describe 'when argument is an IpAddr object' do
86
+ before :all do
87
+ @result = DataMapper::Types::IPAddress.typecast(@input, :property)
88
+ end
89
+
90
+ it 'does not change the value' do
91
+ @result.should == @input
92
+ end
93
+ end
94
+
95
+ describe 'when argument is a valid IP address as a string' do
96
+ before :all do
97
+ @result = DataMapper::Types::IPAddress.typecast(@stored, :property)
98
+ end
99
+
100
+ it 'instantiates IPAddr instance' do
101
+ @result.should == @input
102
+ end
103
+ end
53
104
  end
54
105
  end
55
-
56
106
  end
@@ -1,53 +1,120 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname.parent.expand_path + 'spec_helper'
1
+ require 'spec_helper'
2
+ require 'shared/identity_function_group'
3
3
 
4
- describe DataMapper::Types::Json, ".load" do
5
- it 'should return nil if nil is provided' do
6
- DataMapper::Types::Json.load(nil, :property).should be_nil
7
- end
4
+ try_spec do
5
+ describe DataMapper::Types::Json do
6
+ describe '.load' do
7
+ describe 'when nil is provided' do
8
+ it 'returns nil' do
9
+ DataMapper::Types::Json.load(nil, :property).should be_nil
10
+ end
11
+ end
8
12
 
9
- it 'should parse the value if a string is provided' do
10
- JSON.should_receive(:load).with('json_string').once
11
- DataMapper::Types::Json.load('json_string', :property)
12
- end
13
+ describe 'when Json encoded primitive string is provided' do
14
+ it 'returns decoded value as Ruby string' do
15
+ DataMapper::Types::Json.load(JSON.dump(:value => 'JSON encoded string'), :property).should == { 'value' => 'JSON encoded string' }
16
+ end
17
+ end
13
18
 
14
- it 'should raise an ArgumentError if something else is given' do
15
- lambda {
16
- DataMapper::Types::Json.load(:sym, :property)
17
- }.should raise_error(ArgumentError, '+value+ must be nil or a String')
18
- end
19
- end
19
+ describe 'when something else is provided' do
20
+ it 'raises ArgumentError with a meaningful message' do
21
+ lambda {
22
+ DataMapper::Types::Json.load(:sym, :property)
23
+ }.should raise_error(ArgumentError, '+value+ of a property of JSON type must be nil or a String')
24
+ end
25
+ end
26
+ end
20
27
 
21
- describe DataMapper::Types::Json, ".dump" do
22
- it 'should return nil if the value is nil' do
23
- DataMapper::Types::Json.dump(nil, :property).should be_nil
24
- end
28
+ describe '.dump' do
29
+ describe 'when nil is provided' do
30
+ it 'returns nil' do
31
+ DataMapper::Types::Json.dump(nil, :property).should be_nil
32
+ end
33
+ end
25
34
 
26
- it 'should do nothing if the value is a string' do
27
- JSON.should_not_receive(:dump)
28
- DataMapper::Types::Json.dump('', :property).should be_kind_of(String)
29
- end
35
+ describe 'when Json encoded primitive string is provided' do
36
+ it 'does not do double encoding' do
37
+ DataMapper::Types::Json.dump('Json encoded string', :property).should == 'Json encoded string'
38
+ end
39
+ end
30
40
 
31
- it 'should dump to a JSON string otherwise' do
32
- JSON.should_receive(:dump).with([]).once
33
- DataMapper::Types::Json.dump([], :property)
34
- end
35
- end
41
+ describe 'when regular Ruby string is provided' do
42
+ it 'dumps argument to Json' do
43
+ DataMapper::Types::Json.dump('dump me (to JSON)', :property).should == 'dump me (to JSON)'
44
+ end
45
+ end
36
46
 
37
- describe DataMapper::Types::Json, ".typecast" do
38
- it 'should parse the value if a string is provided' do
39
- JSON.should_receive(:load).with('json_string')
47
+ describe 'when Ruby array is provided' do
48
+ it 'dumps argument to Json' do
49
+ DataMapper::Types::Json.dump([1, 2, 3], :property).should == '[1,2,3]'
50
+ end
51
+ end
40
52
 
41
- DataMapper::Types::Json.typecast('json_string', :property)
42
- end
53
+ describe 'when Ruby hash is provided' do
54
+ it 'dumps argument to Json' do
55
+ DataMapper::Types::Json.dump({ :datamapper => 'Data access layer in Ruby' }, :property).
56
+ should == '{"datamapper":"Data access layer in Ruby"}'
57
+ end
58
+ end
59
+ end
43
60
 
44
- it 'should leave the value alone if an array is given' do
45
- JSON.should_not_receive(:load)
46
- DataMapper::Types::Json.typecast([], :property)
47
- end
61
+ describe '.typecast' do
62
+ class SerializeMe
63
+ attr_accessor :name
64
+ end
65
+
66
+ describe 'when given instance of a Hash' do
67
+ before :all do
68
+ @input = { :library => 'DataMapper' }
69
+
70
+ @result = DataMapper::Types::Json.typecast(@input, :property)
71
+ end
72
+
73
+ it_should_behave_like 'identity function'
74
+ end
75
+
76
+ describe 'when given instance of an Array' do
77
+ before :all do
78
+ @input = %w[ dm-core dm-more ]
79
+
80
+ @result = DataMapper::Types::Json.typecast(@input, :property)
81
+ end
82
+
83
+ it_should_behave_like 'identity function'
84
+ end
85
+
86
+ describe 'when given nil' do
87
+ before :all do
88
+ @input = nil
89
+
90
+ @result = DataMapper::Types::Json.typecast(@input, :property)
91
+ end
92
+
93
+ it_should_behave_like 'identity function'
94
+ end
95
+
96
+ describe 'when given JSON encoded value' do
97
+ before :all do
98
+ @input = '{ "value": 11 }'
99
+
100
+ @result = DataMapper::Types::Json.typecast(@input, :property)
101
+ end
102
+
103
+ it 'decodes value from JSON' do
104
+ @result.should == { 'value' => 11 }
105
+ end
106
+ end
107
+
108
+ describe 'when given instance of a custom class' do
109
+ before :all do
110
+ @input = SerializeMe.new
111
+ @input.name = 'Hello!'
112
+
113
+ # @result = DataMapper::Types::Json.typecast(@input, :property)
114
+ end
48
115
 
49
- it 'should leave the value alone if a hash is given' do
50
- JSON.should_not_receive(:load)
51
- DataMapper::Types::Json.typecast({}, :property)
116
+ it 'attempts to load value from JSON string'
117
+ end
118
+ end
52
119
  end
53
120
  end