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,23 +1,53 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname.parent.expand_path + 'spec_helper'
1
+ require 'spec_helper'
3
2
 
4
- describe DataMapper::Types::Regexp, ".load" do
5
- it 'should make a Regexp from the value if a string is provided' do
6
- Regexp.should_receive(:new).with('regexp_string').once
7
- DataMapper::Types::Regexp.load('regexp_string', :property)
8
- end
3
+ try_spec do
4
+ describe DataMapper::Types::Regexp do
5
+ describe '.load' do
6
+ describe 'when argument is a string' do
7
+ before :all do
8
+ @input = '[a-z]\d+'
9
+ @result = DataMapper::Types::Regexp.load(@input, :property)
10
+ end
9
11
 
10
- it 'should return nil otherwise' do
11
- DataMapper::Types::Regexp.load(nil, :property).should == nil
12
- end
13
- end
12
+ it 'create a regexp instance from argument' do
13
+ @result.should == Regexp.new(@input)
14
+ end
15
+ end
14
16
 
15
- describe DataMapper::Types::Regexp, ".dump" do
16
- it 'should dump to a string' do
17
- DataMapper::Types::Regexp.dump(/\d+/, :property).should == "\\d+"
18
- end
17
+ describe 'when argument is nil' do
18
+ before :all do
19
+ @input = nil
20
+ @result = DataMapper::Types::Regexp.load(@input, :property)
21
+ end
22
+
23
+ it 'returns nil' do
24
+ @result.should be_nil
25
+ end
26
+ end
27
+ end
28
+
29
+ describe '.dump' do
30
+ describe 'when argument is a regular expression' do
31
+ before :all do
32
+ @input = /\d+/
33
+ @result = DataMapper::Types::Regexp.dump(@input, :property)
34
+ end
35
+
36
+ it 'escapes the argument' do
37
+ @result.should == '\\d+'
38
+ end
39
+ end
40
+
41
+ describe 'when argument is nil' do
42
+ before :all do
43
+ @input = nil
44
+ @result = DataMapper::Types::Regexp.dump(@input, :property)
45
+ end
19
46
 
20
- it 'should return nil if the value is nil' do
21
- DataMapper::Types::Regexp.dump(nil, :property).should == nil
47
+ it 'returns nil' do
48
+ @result.should be_nil
49
+ end
50
+ end
51
+ end
22
52
  end
23
53
  end
@@ -1,49 +1,60 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname.parent.expand_path + 'spec_helper'
3
-
4
- describe DataMapper::Types::URI do
5
-
6
- before(:each) do
7
- @uri_str = "http://example.com/path/to/resource/"
8
- @uri = Addressable::URI.parse(@uri_str)
9
- end
10
-
11
- describe ".dump" do
12
- it "should return the URI as a String" do
13
- DataMapper::Types::URI.dump(@uri, :property).should == @uri_str
14
- end
15
-
16
- it "should return nil if the String is nil" do
17
- DataMapper::Types::URI.dump(nil, :property).should be_nil
18
- end
19
-
20
- it "should return an empty URI if the String is empty" do
21
- DataMapper::Types::URI.dump("", :property).should == ""
22
- end
23
- end
24
-
25
- describe ".load" do
26
- it "should return the URI as Addressable" do
27
- DataMapper::Types::URI.load(@uri_str, :property).should == @uri
28
- end
29
-
30
- it "should return nil if given nil" do
31
- DataMapper::Types::URI.load(nil, :property).should be_nil
32
- end
33
-
34
- it "should return an empty URI if given an empty String" do
35
- DataMapper::Types::URI.load("", :property).should == Addressable::URI.parse("")
36
- end
37
- end
38
-
39
- describe '.typecast' do
40
- it 'should do nothing if an Addressable::URI is provided' do
41
- DataMapper::Types::URI.typecast(@uri, :property).should == @uri
42
- end
43
-
44
- it 'should defer to .load if a string is provided' do
45
- DataMapper::Types::URI.should_receive(:load).with(@uri_str, :property)
46
- DataMapper::Types::URI.typecast(@uri_str, :property)
1
+ require 'spec_helper'
2
+
3
+ try_spec do
4
+ describe DataMapper::Types::URI do
5
+ before do
6
+ @uri_str = 'http://example.com/path/to/resource/'
7
+ @uri = Addressable::URI.parse(@uri_str)
8
+ end
9
+
10
+ describe '.dump' do
11
+ it 'returns the URI as a String' do
12
+ DataMapper::Types::URI.dump(@uri, :property).should == @uri_str
13
+ end
14
+
15
+ describe 'when given nil' do
16
+ it 'returns nil' do
17
+ DataMapper::Types::URI.dump(nil, :property).should be_nil
18
+ end
19
+ end
20
+
21
+ describe 'when given an empty string' do
22
+ it 'returns an empty URI' do
23
+ DataMapper::Types::URI.dump('', :property).should == ''
24
+ end
25
+ end
26
+ end
27
+
28
+ describe '.load' do
29
+ it 'returns the URI as Addressable' do
30
+ DataMapper::Types::URI.load(@uri_str, :property).should == @uri
31
+ end
32
+
33
+ describe 'when given nil' do
34
+ it 'returns nil' do
35
+ DataMapper::Types::URI.load(nil, :property).should be_nil
36
+ end
37
+ end
38
+
39
+ describe 'if given an empty String' do
40
+ it 'returns an empty URI' do
41
+ DataMapper::Types::URI.load('', :property).should == Addressable::URI.parse('')
42
+ end
43
+ end
44
+ end
45
+
46
+ describe '.typecast' do
47
+ describe 'given instance of Addressable::URI' do
48
+ it 'does nothing' do
49
+ DataMapper::Types::URI.typecast(@uri, :property).should == @uri
50
+ end
51
+ end
52
+
53
+ describe 'when given a string' do
54
+ it 'delegates to .load' do
55
+ DataMapper::Types::URI.typecast(@uri_str, :property).should == @uri
56
+ end
57
+ end
47
58
  end
48
59
  end
49
60
  end
@@ -1,58 +1,104 @@
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::Yaml, ".load" do
5
- it 'should return nil if nil is provided' do
6
- DataMapper::Types::Yaml.load(nil, :property).should be_nil
7
- end
8
-
9
- it 'should parse the value if a string is provided' do
10
- YAML.should_receive(:load).with('yaml_string').once
11
- DataMapper::Types::Yaml.load('yaml_string', :property)
12
- end
4
+ try_spec do
5
+ describe DataMapper::Types::Yaml do
6
+ describe '.load' do
7
+ describe 'when nil is provided' do
8
+ it 'returns nil' do
9
+ DataMapper::Types::Yaml.load(nil, :property).should be_nil
10
+ end
11
+ end
13
12
 
14
- it 'should raise an ArgumentError if something else is given' do
15
- lambda {
16
- DataMapper::Types::Yaml.load(:sym, :property)
17
- }.should raise_error(ArgumentError, '+value+ must be nil or a String')
18
- end
19
- end
13
+ describe 'when YAML encoded primitive string is provided' do
14
+ it 'returns decoded value as Ruby string' do
15
+ DataMapper::Types::Yaml.load("--- yaml string\n", :property).should == 'yaml string'
16
+ end
17
+ end
20
18
 
21
- describe DataMapper::Types::Yaml, ".dump" do
22
- it 'should return nil if the value is nil' do
23
- DataMapper::Types::Yaml.dump(nil, :property).should be_nil
24
- end
19
+ describe 'when something else is provided' do
20
+ it 'raises ArgumentError with a meaningful message' do
21
+ lambda {
22
+ DataMapper::Types::Yaml.load(:sym, :property)
23
+ }.should raise_error(ArgumentError, '+value+ of a property of YAML type must be nil or a String')
24
+ end
25
+ end
26
+ end
25
27
 
26
- it 'should do nothing if the value is a string which begins with ---' do
27
- YAML.should_not_receive(:dump)
28
- DataMapper::Types::Yaml.dump('--- str', :property).should be_kind_of(String)
29
- end
28
+ describe '.dump' do
29
+ describe 'when nil is provided' do
30
+ it 'returns nil' do
31
+ DataMapper::Types::Yaml.dump(nil, :property).should be_nil
32
+ end
33
+ end
30
34
 
31
- it 'should dump to a YAML string if the value is a normal string' do
32
- YAML.should_receive(:dump).with('string').once
33
- DataMapper::Types::Yaml.dump('string', :property)
34
- end
35
+ describe 'when YAML encoded primitive string is provided' do
36
+ it 'does not do double encoding' do
37
+ DataMapper::Types::Yaml.dump("--- yaml encoded string\n", :property).should == "--- yaml encoded string\n"
38
+ end
39
+ end
35
40
 
36
- it 'should dump to a YAML string otherwise' do
37
- YAML.should_receive(:dump).with([]).once
38
- DataMapper::Types::Yaml.dump([], :property)
39
- end
40
- end
41
+ describe 'when regular Ruby string is provided' do
42
+ it 'dumps argument to YAML' do
43
+ DataMapper::Types::Yaml.dump('dump me (to yaml)', :property).should == "--- dump me (to yaml)\n"
44
+ end
45
+ end
41
46
 
42
- describe DataMapper::Types::Yaml, ".typecast" do
43
- it 'should leave the value alone' do
44
- @type = DataMapper::Types::Yaml
45
- @type.typecast([1, 2, 3], :property).should == [1, 2, 3]
47
+ describe 'when Ruby array is provided' do
48
+ it 'dumps argument to YAML' do
49
+ DataMapper::Types::Yaml.dump([1, 2, 3], :property).should == "--- \n- 1\n- 2\n- 3\n"
50
+ end
51
+ end
46
52
 
47
- class SerializeMe
48
- attr_accessor :name
53
+ describe 'when Ruby hash is provided' do
54
+ it 'dumps argument to YAML' do
55
+ DataMapper::Types::Yaml.dump({ :datamapper => 'Data access layer in Ruby' }, :property).should == "--- \n:datamapper: Data access layer in Ruby\n"
56
+ end
57
+ end
49
58
  end
50
59
 
51
- obj = SerializeMe.new
52
- obj.name = 'Hello!'
60
+ describe '.typecast' do
61
+ class SerializeMe
62
+ attr_accessor :name
63
+ end
64
+
65
+ describe 'given a number' do
66
+ before :all do
67
+ @input = 15
68
+ @result = 15
69
+ end
70
+
71
+ it_should_behave_like 'identity function'
72
+ end
73
+
74
+ describe 'given an Array instance' do
75
+ before :all do
76
+ @input = ['dm-core', 'dm-more']
77
+ @result = ['dm-core', 'dm-more']
78
+ end
79
+
80
+ it_should_behave_like 'identity function'
81
+ end
53
82
 
54
- casted = @type.typecast(obj, :property)
55
- casted.should be_kind_of(SerializeMe)
56
- casted.name.should == 'Hello!'
83
+ describe 'given a Hash instance' do
84
+ before :all do
85
+ @input = { :format => 'yaml' }
86
+ @result = { :format => 'yaml' }
87
+ end
88
+
89
+ it_should_behave_like 'identity function'
90
+ end
91
+
92
+ describe 'given a plain old Ruby object' do
93
+ before :all do
94
+ @input = SerializeMe.new
95
+ @input.name = 'yamly'
96
+
97
+ @result = @input
98
+ end
99
+
100
+ it_should_behave_like 'identity function'
101
+ end
102
+ end
57
103
  end
58
104
  end
data/tasks/install.rb CHANGED
@@ -4,7 +4,7 @@ end
4
4
 
5
5
  desc "Install #{GEM_NAME} #{GEM_VERSION}"
6
6
  task :install => [ :package ] do
7
- sudo_gem "install --local pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources"
7
+ sudo_gem "install pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources"
8
8
  end
9
9
 
10
10
  desc "Uninstall #{GEM_NAME} #{GEM_VERSION}"
data/tasks/spec.rb CHANGED
@@ -1,6 +1,4 @@
1
1
  begin
2
- gem 'rspec', '~>1.2'
3
- require 'spec'
4
2
  require 'spec/rake/spectask'
5
3
 
6
4
  task :default => [ :spec ]
@@ -8,16 +6,18 @@ begin
8
6
  desc 'Run specifications'
9
7
  Spec::Rake::SpecTask.new(:spec) do |t|
10
8
  t.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
11
- t.spec_files = Pathname.glob((ROOT + 'spec/**/*_spec.rb').to_s).map { |f| f.to_s }
9
+ t.libs << 'lib' << 'spec' # needed for CI rake spec task, duplicated in spec_helper
12
10
 
13
11
  begin
14
- gem 'rcov', '~>0.8'
12
+ require 'rcov'
15
13
  t.rcov = JRUBY ? false : (ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true)
16
14
  t.rcov_opts << '--exclude' << 'spec'
17
15
  t.rcov_opts << '--text-summary'
18
16
  t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
19
17
  rescue LoadError
20
18
  # rcov not installed
19
+ rescue SyntaxError
20
+ # rcov syntax invalid
21
21
  end
22
22
  end
23
23
  rescue LoadError
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-types
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.11
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Smoot
@@ -9,29 +9,10 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-29 00:00:00 -07:00
12
+ date: 2009-09-16 00:00:00 -07:00
13
13
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: dm-core
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - "="
22
- - !ruby/object:Gem::Version
23
- version: 0.9.11
24
- version:
25
- - !ruby/object:Gem::Dependency
26
- name: addressable
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ~>
32
- - !ruby/object:Gem::Version
33
- version: 2.0.2
34
- version:
14
+ dependencies: []
15
+
35
16
  description: DataMapper plugin providing extra data types
36
17
  email:
37
18
  - ssmoot [a] gmail [d] com
@@ -40,19 +21,20 @@ executables: []
40
21
  extensions: []
41
22
 
42
23
  extra_rdoc_files:
43
- - README.txt
24
+ - README.rdoc
44
25
  - LICENSE
45
26
  - TODO
46
- - History.txt
27
+ - History.rdoc
47
28
  files:
48
- - History.txt
29
+ - History.rdoc
49
30
  - LICENSE
50
31
  - Manifest.txt
51
- - README.txt
32
+ - README.rdoc
52
33
  - Rakefile
53
34
  - TODO
54
35
  - lib/dm-types.rb
55
36
  - lib/dm-types/bcrypt_hash.rb
37
+ - lib/dm-types/comma_separated_list.rb
56
38
  - lib/dm-types/csv.rb
57
39
  - lib/dm-types/enum.rb
58
40
  - lib/dm-types/epoch_time.rb
@@ -61,13 +43,21 @@ files:
61
43
  - lib/dm-types/ip_address.rb
62
44
  - lib/dm-types/json.rb
63
45
  - lib/dm-types/regexp.rb
64
- - lib/dm-types/serial.rb
65
46
  - lib/dm-types/slug.rb
66
47
  - lib/dm-types/uri.rb
67
48
  - lib/dm-types/uuid.rb
68
49
  - lib/dm-types/version.rb
69
50
  - lib/dm-types/yaml.rb
51
+ - spec/fixtures/article.rb
52
+ - spec/fixtures/bookmark.rb
53
+ - spec/fixtures/invention.rb
54
+ - spec/fixtures/network_node.rb
55
+ - spec/fixtures/person.rb
56
+ - spec/fixtures/software_package.rb
57
+ - spec/fixtures/ticket.rb
58
+ - spec/fixtures/tshirt.rb
70
59
  - spec/integration/bcrypt_hash_spec.rb
60
+ - spec/integration/comma_separated_list_spec.rb
71
61
  - spec/integration/enum_spec.rb
72
62
  - spec/integration/file_path_spec.rb
73
63
  - spec/integration/flag_spec.rb
@@ -77,6 +67,7 @@ files:
77
67
  - spec/integration/uri_spec.rb
78
68
  - spec/integration/uuid_spec.rb
79
69
  - spec/integration/yaml_spec.rb
70
+ - spec/shared/identity_function_group.rb
80
71
  - spec/spec.opts
81
72
  - spec/spec_helper.rb
82
73
  - spec/unit/bcrypt_hash_spec.rb
@@ -93,11 +84,13 @@ files:
93
84
  - tasks/install.rb
94
85
  - tasks/spec.rb
95
86
  has_rdoc: true
96
- homepage: http://github.com/sam/dm-more/tree/master/dm-types
87
+ homepage: http://github.com/datamapper/dm-more/tree/master/dm-types
88
+ licenses: []
89
+
97
90
  post_install_message:
98
91
  rdoc_options:
99
92
  - --main
100
- - README.txt
93
+ - README.rdoc
101
94
  require_paths:
102
95
  - lib
103
96
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -115,9 +108,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
108
  requirements: []
116
109
 
117
110
  rubyforge_project: datamapper
118
- rubygems_version: 1.3.1
111
+ rubygems_version: 1.3.5
119
112
  signing_key:
120
- specification_version: 2
113
+ specification_version: 3
121
114
  summary: DataMapper plugin providing extra data types
122
115
  test_files: []
123
116