Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
[slug] Escape the value when typecasting
Browse files Browse the repository at this point in the history
[#1212 state:resolved]
  • Loading branch information
solnic committed May 23, 2010
1 parent ae851ab commit 561f63f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/dm-types/slug.rb
Expand Up @@ -9,7 +9,7 @@ class Slug < String
# not exceed the maximum URI length either.
length 2000

def dump(value)
def typecast(value)
return if value.nil?

if value.respond_to?(:to_str)
Expand Down
16 changes: 11 additions & 5 deletions spec/integration/slug_spec.rb
Expand Up @@ -36,19 +36,25 @@
["La ley antipiratería reduce un 33% el tráfico online en Suecia", 'la-ley-antipirateria-reduce-un-33-percent-el-trafico-online-en-suecia'],
["L'Etat américain du Texas s'apprête à interdire Windows Vista", 'letat-americain-du-texas-sapprete-a-interdire-windows-vista']
].each do |title, slug|
describe "persisted with title '#{title}'" do
describe "set with title '#{title}'" do
before :all do
@resource = DataMapper::Types::Fixtures::Article.new(:title => title)
@resource.save.should be_true
@resource.reload
@resource.valid?.should be(true)
end

it "has slug equal to '#{slug}'" do
@resource.slug.should == slug
end

it 'can be found by slug' do
DataMapper::Types::Fixtures::Article.first(:slug => slug).should == @resource
describe "and persisted" do
before :all do
@resource.save.should be(true)
@resource.reload
end

it 'can be found by slug' do
DataMapper::Types::Fixtures::Article.first(:slug => slug).should == @resource
end
end
end
end
Expand Down

0 comments on commit 561f63f

Please sign in to comment.