Permalink
Browse files

Adds DataMapper::Type::Stub replacing DataMapper::Type::Permalink. Ta…

…lked with Sam prior to committing
  • Loading branch information...
1 parent d7ce3d0 commit ec7ede785724d90d2644d0fcd7bbf4dd6bf22444 @hassox hassox committed Oct 8, 2008
View
2 dm-types/lib/dm-types.rb
@@ -18,7 +18,7 @@
require dir / 'yaml'
require dir / 'serial'
require dir / 'regexp'
-require dir / 'permalink'
+require dir / 'stub'
# this looks a little ugly, but everyone who uses dm-types shouldn't have to have ruby-bcrypt installed
module DataMapper
View
13 dm-types/lib/dm-types/permalink.rb → dm-types/lib/dm-types/stub.rb
@@ -2,25 +2,24 @@
module DataMapper
module Types
- class Permalink < DataMapper::Type
+ class Stub < DataMapper::Type
primitive String
size 65535
def self.load(value, property)
+ value
+ end
+
+ def self.dump(value, property)
if value.nil?
nil
elsif value.is_a?(String)
- Iconv.new('UTF-8//TRANSLIT//IGNORE', 'UTF-8').iconv(value.gsub(/[^\w\s\-\—]/,'').gsub(/[^\w]|[\_]/,' ').split.join('-').downcase)
+ Iconv.new('UTF-8//TRANSLIT//IGNORE', 'UTF-8').iconv(value.gsub(/[^\w\s\-\—]/,'').gsub(/[^\w]|[\_]/,' ').split.join('-').downcase).to_s
else
raise ArgumentError.new("+value+ must be nil or a String")
end
end
- def self.dump(value, property)
- return nil if value.nil?
- value.to_s
- end
-
end # class Permalink
end # module Types
end # module DataMapper
View
31 dm-types/spec/integration/permalink_spec.rb
@@ -1,31 +0,0 @@
-require 'pathname'
-require 'iconv'
-require Pathname(__FILE__).dirname.parent.expand_path + 'spec_helper'
-
-describe DataMapper::Types::Permalink do
-
- before(:all) do
- class PermalinkTest
- include DataMapper::Resource
-
- property :id, Serial
- property :name, Permalink
-
- end
- PermalinkTest.auto_migrate!
- end
-
- it "should create the permalink" do
- repository(:default) do
- PermalinkTest.create(:name => 'New DataMapper Type')
- end
-
- PermalinkTest.first.name.should == create_permalink("New DataMapper Type")
- end
-
-
- def create_permalink(word)
- Iconv.new('UTF-8//TRANSLIT//IGNORE', 'UTF-8').iconv(word.gsub(/[^\w\s\-\—]/,'').gsub(/[^\w]|[\_]/,' ').split.join('-').downcase)
- end
-
-end
View
42 dm-types/spec/integration/stub_spec.rb
@@ -0,0 +1,42 @@
+require 'pathname'
+require 'iconv'
+require Pathname(__FILE__).dirname.parent.expand_path + 'spec_helper'
+
+describe DataMapper::Types::Stub do
+
+ before(:all) do
+ class StubTest
+ include DataMapper::Resource
+
+ property :id, Serial
+ property :name, Stub
+
+ end
+ StubTest.auto_migrate!
+ end
+
+ it "should create the permalink" do
+ repository(:default) do
+ StubTest.create(:name => 'New DataMapper Type')
+ end
+
+ StubTest.first.name.should == create_stub("New DataMapper Type")
+ end
+
+ it "should find by a stub" do
+ repository(:default) do
+ StubTest.create(:name => "This Should Be a Stub")
+ end
+ stub = create_stub( "This Should Be a Stub")
+
+ stubbed = StubTest.first(:name => stub)
+ stubbed.should_not be_nil
+ stubbed.name.should == stub
+ end
+
+
+ def create_stub(word)
+ Iconv.new('UTF-8//TRANSLIT//IGNORE', 'UTF-8').iconv(word.gsub(/[^\w\s\-\—]/,'').gsub(/[^\w]|[\_]/,' ').split.join('-').downcase)
+ end
+
+end

0 comments on commit ec7ede7

Please sign in to comment.