dm-types 0.9.7 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1 +1,6 @@
1
+ === 0.9.8 / 2008-12-07
1
2
 
3
+ * 2 bug fixes:
4
+
5
+ * Corrected BCryptHash type behavior (previously, value would be repeated saved
6
+ * tightened uuidtools requirement for the uuid type
data/Manifest.txt CHANGED
@@ -43,3 +43,5 @@ spec/unit/json_spec.rb
43
43
  spec/unit/regexp_spec.rb
44
44
  spec/unit/uri_spec.rb
45
45
  spec/unit/yaml_spec.rb
46
+ tasks/install.rb
47
+ tasks/spec.rb
data/Rakefile CHANGED
@@ -1,58 +1,25 @@
1
- require 'rubygems'
2
- require 'spec'
3
- require 'spec/rake/spectask'
4
1
  require 'pathname'
2
+ require 'rubygems'
3
+
4
+ ROOT = Pathname(__FILE__).dirname.expand_path
5
+ JRUBY = RUBY_PLATFORM =~ /java/
6
+ WINDOWS = Gem.win_platform?
7
+ SUDO = (WINDOWS || JRUBY) ? '' : ('sudo' unless ENV['SUDOLESS'])
5
8
 
6
- ROOT = Pathname(__FILE__).dirname.expand_path
7
9
  require ROOT + 'lib/dm-types/version'
8
10
 
9
- AUTHOR = "Sam Smoot"
10
- EMAIL = "ssmoot@gmail.com"
11
- GEM_NAME = "dm-types"
11
+ AUTHOR = 'Sam Smoot'
12
+ EMAIL = 'ssmoot [a] gmail [d] com'
13
+ GEM_NAME = 'dm-types'
12
14
  GEM_VERSION = DataMapper::Types::VERSION
13
- GEM_DEPENDENCIES = [["dm-core", GEM_VERSION], "uuidtools"]
14
- GEM_CLEAN = ["log", "pkg", "coverage"]
15
- GEM_EXTRAS = { :has_rdoc => true, :extra_rdoc_files => %w[ README.txt LICENSE TODO ] }
16
-
17
- PROJECT_NAME = "datamapper"
18
- PROJECT_URL = "http://github.com/sam/dm-more/tree/master/dm-types"
19
- PROJECT_DESCRIPTION = PROJECT_SUMMARY = "DataMapper plugin providing extra data types"
20
-
21
- require ROOT.parent + 'tasks/hoe'
22
-
23
- task :default => [ :spec ]
24
-
25
- WIN32 = (RUBY_PLATFORM =~ /win32|mingw|cygwin/) rescue nil
26
- SUDO = WIN32 ? '' : ('sudo' unless ENV['SUDOLESS'])
27
-
28
- desc "Install #{GEM_NAME} #{GEM_VERSION} (default ruby)"
29
- task :install => [ :package ] do
30
- sh "#{SUDO} gem install --local pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources", :verbose => false
31
- end
32
-
33
- desc "Uninstall #{GEM_NAME} #{GEM_VERSION} (default ruby)"
34
- task :uninstall => [ :clobber ] do
35
- sh "#{SUDO} gem uninstall #{GEM_NAME} -v#{GEM_VERSION} -I -x", :verbose => false
36
- end
37
-
38
- namespace :jruby do
39
- desc "Install #{GEM_NAME} #{GEM_VERSION} with JRuby"
40
- task :install => [ :package ] do
41
- sh %{#{SUDO} jruby -S gem install --local pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources}, :verbose => false
42
- end
43
- end
15
+ GEM_DEPENDENCIES = [['dm-core', "~>#{GEM_VERSION}"], ['addressable', '~>2.0.1']]
16
+ GEM_CLEAN = %w[ log pkg coverage ]
17
+ GEM_EXTRAS = { :has_rdoc => true, :extra_rdoc_files => %w[ README.txt LICENSE TODO History.txt ] }
44
18
 
45
- desc 'Run specifications'
46
- Spec::Rake::SpecTask.new(:spec) do |t|
47
- t.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
48
- t.spec_files = Pathname.glob((ROOT + 'spec/**/*_spec.rb').to_s)
19
+ PROJECT_NAME = 'datamapper'
20
+ PROJECT_URL = "http://github.com/sam/dm-more/tree/master/#{GEM_NAME}"
21
+ PROJECT_DESCRIPTION = PROJECT_SUMMARY = 'DataMapper plugin providing extra data types'
49
22
 
50
- begin
51
- t.rcov = ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true
52
- t.rcov_opts << '--exclude' << 'spec'
53
- t.rcov_opts << '--text-summary'
54
- t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
55
- rescue Exception
56
- # rcov not installed
57
- end
23
+ [ ROOT, ROOT.parent ].each do |dir|
24
+ Pathname.glob(dir.join('tasks/**/*.rb').to_s).each { |f| require f }
58
25
  end
data/TODO CHANGED
@@ -1,8 +0,0 @@
1
- TODO
2
- ====
3
-
4
-
5
-
6
- ---
7
- TODO tickets may also be found in the DataMapper Issue Tracker:
8
- http://wm.lighthouseapp.com/projects/4819-datamapper/overview
data/lib/dm-types.rb CHANGED
@@ -1,28 +1,26 @@
1
- require 'rubygems'
2
1
  require 'pathname'
2
+ require 'rubygems'
3
3
 
4
- gem 'dm-core', '~>0.9.7'
4
+ gem 'dm-core', '~>0.9.8'
5
5
  require 'dm-core'
6
6
 
7
- dir = Pathname(__FILE__).dirname.expand_path / 'dm-types'
8
-
9
- require dir / 'csv'
10
- require dir / 'enum'
11
- require dir / 'epoch_time'
12
- require dir / 'file_path'
13
- require dir / 'flag'
14
- require dir / 'ip_address'
15
- require dir / "json"""
16
- require dir / 'uri'
17
- require dir / 'uuid'
18
- require dir / 'yaml'
19
- require dir / 'serial'
20
- require dir / 'regexp'
21
- require dir / 'slug'
22
-
23
- # this looks a little ugly, but everyone who uses dm-types shouldn't have to have ruby-bcrypt installed
24
7
  module DataMapper
25
8
  module Types
26
- autoload(:BCryptHash, File.join(Pathname(__FILE__).dirname.expand_path, 'dm-types', 'bcrypt_hash'))
9
+ dir = (Pathname(__FILE__).dirname.expand_path / 'dm-types').to_s
10
+
11
+ autoload :BCryptHash, dir / 'bcrypt_hash'
12
+ autoload :Csv, dir / 'csv'
13
+ autoload :Enum, dir / 'enum'
14
+ autoload :EpochTime, dir / 'epoch_time'
15
+ autoload :FilePath, dir / 'file_path'
16
+ autoload :Flag, dir / 'flag'
17
+ autoload :IPAddress, dir / 'ip_address'
18
+ autoload :Json, dir / 'json'
19
+ autoload :Regexp, dir / 'regexp'
20
+ autoload :Serial, dir / 'serial'
21
+ autoload :Slug, dir / 'slug'
22
+ autoload :URI, dir / 'uri'
23
+ autoload :UUID, dir / 'uuid'
24
+ autoload :Yaml, dir / 'yaml'
27
25
  end
28
26
  end
@@ -1,4 +1,6 @@
1
+ require 'rubygems'
1
2
 
3
+ gem 'bcrypt-ruby', '~>2.0.3'
2
4
  require 'bcrypt'
3
5
 
4
6
  module DataMapper
@@ -8,22 +10,22 @@ module DataMapper
8
10
  size 60
9
11
 
10
12
  def self.load(value, property)
11
- if value.nil?
12
- nil
13
- elsif value.is_a?(String)
14
- BCrypt::Password.new(value)
15
- else
16
- raise ArgumentError.new("+value+ must be nil or a String")
17
- end
13
+ typecast(value, property)
18
14
  end
19
15
 
20
16
  def self.dump(value, property)
17
+ typecast(value, property)
18
+ end
19
+
20
+ def self.typecast(value, property)
21
21
  if value.nil?
22
22
  nil
23
- elsif value.is_a?(String)
24
- BCrypt::Password.create(value, :cost => BCrypt::Engine::DEFAULT_COST)
25
23
  else
26
- raise ArgumentError.new("+value+ must be nil or a String")
24
+ begin
25
+ value.is_a?(BCrypt::Password) ? value : BCrypt::Password.new(value)
26
+ rescue BCrypt::Errors::InvalidHash
27
+ BCrypt::Password.create(value, :cost => BCrypt::Engine::DEFAULT_COST)
28
+ end
27
29
  end
28
30
  end
29
31
  end # class BCryptHash
data/lib/dm-types/uri.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require 'rubygems'
2
+
3
+ gem 'addressable', '~>2.0.1'
2
4
  require 'addressable/uri'
3
5
 
4
6
  module DataMapper
data/lib/dm-types/uuid.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'rubygems'
2
+
3
+ gem 'uuidtools', '~>1.0.7'
1
4
  require 'uuidtools'
2
5
 
3
6
  module DataMapper
@@ -1,5 +1,5 @@
1
1
  module DataMapper
2
2
  module Types
3
- VERSION = "0.9.7"
3
+ VERSION = '0.9.8'
4
4
  end
5
5
  end
@@ -1,14 +1,14 @@
1
-
2
1
  require 'pathname'
3
2
  require Pathname(__FILE__).dirname.parent.expand_path + 'spec_helper'
4
3
 
5
4
  begin
5
+ gem 'bcrypt-ruby', '~>2.0.3'
6
6
  require 'bcrypt'
7
7
  rescue LoadError
8
8
  skip_tests = true
9
9
  end
10
10
 
11
- describe "DataMapper::Types::BCryptHash" do
11
+ describe 'DataMapper::Types::BCryptHash' do
12
12
  unless skip_tests
13
13
  describe "with no options" do
14
14
  before(:each) do
@@ -19,12 +19,12 @@ describe "DataMapper::Types::BCryptHash" do
19
19
  property :password, BCryptHash
20
20
  end
21
21
  User.auto_migrate!
22
- User.create!(:password => "DataMapper R0cks!")
22
+ User.create(:password => "DataMapper R0cks!")
23
23
  end
24
24
 
25
25
  it "should save a password to the DB on creation" do
26
26
  repository(:default) do
27
- User.create!(:password => "password1")
27
+ User.create(:password => "password1")
28
28
  end
29
29
  user = User.all
30
30
  user[0].password.should == "DataMapper R0cks!"
@@ -39,6 +39,15 @@ describe "DataMapper::Types::BCryptHash" do
39
39
  @user.password.should == "D@t@Mapper R0cks!"
40
40
  end
41
41
 
42
+ it "should not change the password on save and reload" do
43
+ @user = User.first
44
+ v1 = @user.password.to_s
45
+ @user.save
46
+ @user.reload
47
+ v2 = @user.password.to_s
48
+ v1.should == v2
49
+ end
50
+
42
51
  it "should have a cost of BCrypt::Engine::DEFAULT_COST" do
43
52
  @user = User.first
44
53
  @user.password.cost.should == BCrypt::Engine::DEFAULT_COST
@@ -14,7 +14,7 @@ describe DataMapper::Types::FilePath do
14
14
 
15
15
  it "should work" do
16
16
  repository(:default) do
17
- FilePathTest.create!(:path => '/usr')
17
+ FilePathTest.create(:path => '/usr')
18
18
  end
19
19
 
20
20
  FilePathTest.first.path.should == Pathname.new('/usr')
@@ -14,7 +14,7 @@ describe DataMapper::Types::URI do
14
14
 
15
15
  it "should work" do
16
16
  repository(:default) do
17
- URITest.create!(:uri => 'http://localhost')
17
+ URITest.create(:uri => 'http://localhost')
18
18
  end
19
19
 
20
20
  URITest.first.uri.should == Addressable::URI.parse('http://localhost')
@@ -1,38 +1,46 @@
1
1
  require 'pathname'
2
- require 'uuidtools'
3
2
  require Pathname(__FILE__).dirname.parent.expand_path + 'spec_helper'
4
3
 
5
- describe DataMapper::Types::UUID do
4
+ begin
5
+ gem 'uuidtools', '~>1.0.7'
6
+ require 'uuidtools'
7
+ rescue LoadError
8
+ skip_tests = true
9
+ end
6
10
 
7
- before(:all) do
8
- class UUIDTest
9
- include DataMapper::Resource
11
+ describe 'DataMapper::Types::UUID' do
12
+ unless skip_tests
13
+ before(:all) do
14
+ class UUIDTest
15
+ include DataMapper::Resource
10
16
 
11
- property :id, Serial
12
- property :uuid, ::DataMapper::Types::UUID
13
- end
17
+ property :id, Serial
18
+ property :uuid, ::DataMapper::Types::UUID
19
+ end
14
20
 
15
- UUIDTest.auto_migrate!
16
- end
21
+ UUIDTest.auto_migrate!
22
+ end
17
23
 
18
- it "should be settable as a uuid" do
19
- u = UUIDTest.create(:uuid => UUID.parse('b0fc632e-d744-4821-afe3-4ea0701859ee'))
24
+ it "should be settable as a uuid" do
25
+ u = UUIDTest.create(:uuid => UUID.parse('b0fc632e-d744-4821-afe3-4ea0701859ee'))
20
26
 
21
- u.uuid.should be_kind_of(UUID)
22
- u.uuid.to_s.should == 'b0fc632e-d744-4821-afe3-4ea0701859ee'
23
- end
27
+ u.uuid.should be_kind_of(UUID)
28
+ u.uuid.to_s.should == 'b0fc632e-d744-4821-afe3-4ea0701859ee'
29
+ end
24
30
 
25
- it "should be settable as a string" do
26
- u = UUIDTest.create(:uuid => 'b0fc632e-d744-4821-afe3-4ea0701859ee')
31
+ it "should be settable as a string" do
32
+ u = UUIDTest.create(:uuid => 'b0fc632e-d744-4821-afe3-4ea0701859ee')
27
33
 
28
- u.uuid.should be_kind_of(UUID)
29
- u.uuid.to_s.should == 'b0fc632e-d744-4821-afe3-4ea0701859ee'
30
- end
34
+ u.uuid.should be_kind_of(UUID)
35
+ u.uuid.to_s.should == 'b0fc632e-d744-4821-afe3-4ea0701859ee'
36
+ end
31
37
 
32
- it "should be allowed to be null" do
33
- u = UUIDTest.create()
38
+ it "should be allowed to be null" do
39
+ u = UUIDTest.create()
34
40
 
35
- u.uuid.should be_nil
41
+ u.uuid.should be_nil
42
+ end
43
+ else
44
+ it 'requires the uuidtools gem to test'
36
45
  end
37
-
38
46
  end
data/spec/spec.opts CHANGED
@@ -1,2 +1 @@
1
- --format specdoc
2
1
  --colour
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,9 @@
1
+ require 'pathname'
1
2
  require 'rubygems'
2
- gem 'rspec', '>=1.1.3'
3
+
4
+ gem 'rspec', '~>1.1.11'
3
5
  require 'spec'
4
- require 'pathname'
6
+
5
7
  require Pathname(__FILE__).dirname.parent.expand_path + 'lib/dm-types'
6
8
 
7
9
  ENV["SQLITE3_SPEC_URI"] ||= 'sqlite3::memory:'
@@ -18,7 +20,7 @@ def setup_adapter(name, default_uri = nil)
18
20
  rescue Exception => e
19
21
  if name.to_s == ENV['ADAPTER']
20
22
  Object.const_set('ADAPTER', nil)
21
- warn "Could not load #{name} adapter: #{e}"
23
+ warn "Could not load do_#{name}: #{e}"
22
24
  end
23
25
  false
24
26
  end
@@ -4,6 +4,7 @@ require Pathname(__FILE__).dirname.parent.expand_path + 'spec_helper'
4
4
  include DataMapper::Types
5
5
 
6
6
  begin
7
+ gem 'bcrypt-ruby', '~>2.0.3'
7
8
  require 'bcrypt'
8
9
  rescue LoadError
9
10
  skip_tests = true
@@ -15,6 +16,13 @@ describe "DataMapper::Types::BCryptHash" do
15
16
  before(:each) do
16
17
  @clear_password = "DataMapper R0cks!"
17
18
  @crypted_password = BCrypt::Password.create(@clear_password)
19
+ @nonstandard_type = 1
20
+
21
+ class TestType
22
+ @a = 1
23
+ @b = "Hi There"
24
+ end
25
+ @nonstandard_type2 = TestType.new
18
26
  end
19
27
 
20
28
  describe ".dump" do
@@ -23,7 +31,7 @@ describe "DataMapper::Types::BCryptHash" do
23
31
  end
24
32
 
25
33
  it "should return a string that is 60 characters long" do
26
- BCryptHash.dump(@clear_password, :property).should have(60).characters
34
+ BCryptHash.dump(@clear_password, :property).to_s.should have(60).characters
27
35
  end
28
36
 
29
37
  it "should return nil if nil is passed" do
@@ -41,7 +49,53 @@ describe "DataMapper::Types::BCryptHash" do
41
49
  end
42
50
 
43
51
  it "should return nil if given nil" do
44
- FilePath.load(nil, :property).should be_nil
52
+ BCryptHash.load(nil, :property).should be_nil
53
+ end
54
+ end
55
+
56
+ describe ".typecast" do
57
+ it "should return the crypted_password as a BCrypt::Password" do
58
+ BCryptHash.typecast(@crypted_password, :property).should be_an_instance_of(BCrypt::Password)
59
+ end
60
+
61
+ it "should match the password as a BCrypt::Password" do
62
+ BCryptHash.typecast(@crypted_password, :property).should == @clear_password
63
+ end
64
+
65
+ it "should return the string value of crypted_password as a BCrypt::Password" do
66
+ BCryptHash.typecast(@crypted_password.to_s, :property).should be_an_instance_of(BCrypt::Password)
67
+ end
68
+
69
+ it "should match the password as a string of the crypted_password" do
70
+ BCryptHash.typecast(@crypted_password.to_s, :property).should == @clear_password
71
+ end
72
+
73
+ it "should return the password as a BCrypt::Password" do
74
+ BCryptHash.typecast(@clear_password, :property).should be_an_instance_of(BCrypt::Password)
75
+ end
76
+
77
+ it "should match the password as clear_password" do
78
+ BCryptHash.typecast(@clear_password, :property).should == @clear_password
79
+ end
80
+
81
+ it "should encrypt any type that has to_s" do
82
+ BCryptHash.typecast(@nonstandard_type, :property).should be_an_instance_of(BCrypt::Password)
83
+ end
84
+
85
+ it "should match the non-standard type" do
86
+ BCryptHash.typecast(@nonstandard_type, :property).should == @nonstandard_type
87
+ end
88
+
89
+ it "should encrypt anything passed to it" do
90
+ BCryptHash.typecast(@nonstandard_type2, :property).should be_an_instance_of(BCrypt::Password)
91
+ end
92
+
93
+ it "should match user-defined types" do
94
+ BCryptHash.typecast(@nonstandard_type2, :property).should == @nonstandard_type2
95
+ end
96
+
97
+ it "should return nil if given nil" do
98
+ BCryptHash.typecast(nil, :property).should be_nil
45
99
  end
46
100
  end
47
101
  else
data/tasks/install.rb ADDED
@@ -0,0 +1,13 @@
1
+ def sudo_gem(cmd)
2
+ sh "#{SUDO} #{RUBY} -S gem #{cmd}", :verbose => false
3
+ end
4
+
5
+ desc "Install #{GEM_NAME} #{GEM_VERSION}"
6
+ task :install => [ :package ] do
7
+ sudo_gem "install --local pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources"
8
+ end
9
+
10
+ desc "Uninstall #{GEM_NAME} #{GEM_VERSION}"
11
+ task :uninstall => [ :clobber ] do
12
+ sudo_gem "uninstall #{GEM_NAME} -v#{GEM_VERSION} -Ix"
13
+ end
data/tasks/spec.rb ADDED
@@ -0,0 +1,25 @@
1
+ begin
2
+ gem 'rspec', '~>1.1.11'
3
+ require 'spec'
4
+ require 'spec/rake/spectask'
5
+
6
+ task :default => [ :spec ]
7
+
8
+ desc 'Run specifications'
9
+ Spec::Rake::SpecTask.new(:spec) do |t|
10
+ 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)
12
+
13
+ begin
14
+ gem 'rcov', '~>0.8'
15
+ t.rcov = JRUBY ? false : (ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true)
16
+ t.rcov_opts << '--exclude' << 'spec'
17
+ t.rcov_opts << '--text-summary'
18
+ t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
19
+ rescue LoadError
20
+ # rcov not installed
21
+ end
22
+ end
23
+ rescue LoadError
24
+ # rspec not installed
25
+ end
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.7
4
+ version: 0.9.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Smoot
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-11-18 00:00:00 -08:00
12
+ date: 2008-12-07 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -18,33 +18,23 @@ dependencies:
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
21
- - - "="
21
+ - - ~>
22
22
  - !ruby/object:Gem::Version
23
- version: 0.9.7
23
+ version: 0.9.8
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
- name: uuidtools
26
+ name: addressable
27
27
  type: :runtime
28
28
  version_requirement:
29
29
  version_requirements: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: "0"
34
- version:
35
- - !ruby/object:Gem::Dependency
36
- name: hoe
37
- type: :development
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- version: 1.8.2
33
+ version: 2.0.1
44
34
  version:
45
35
  description: DataMapper plugin providing extra data types
46
36
  email:
47
- - ssmoot@gmail.com
37
+ - ssmoot [a] gmail [d] com
48
38
  executables: []
49
39
 
50
40
  extensions: []
@@ -53,6 +43,7 @@ extra_rdoc_files:
53
43
  - README.txt
54
44
  - LICENSE
55
45
  - TODO
46
+ - History.txt
56
47
  files:
57
48
  - History.txt
58
49
  - LICENSE
@@ -99,6 +90,8 @@ files:
99
90
  - spec/unit/regexp_spec.rb
100
91
  - spec/unit/uri_spec.rb
101
92
  - spec/unit/yaml_spec.rb
93
+ - tasks/install.rb
94
+ - tasks/spec.rb
102
95
  has_rdoc: true
103
96
  homepage: http://github.com/sam/dm-more/tree/master/dm-types
104
97
  post_install_message: