Sha256: f9728171a64291830ca4eb6b14ea3652f4fba6d3f3cdf7236db4cbc38a8640c1

Contents?: true

Size: 1.79 KB

Versions: 25

Compression:

Stored size: 1.79 KB

Contents

require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")

describe "Sequel::Plugins::StringStripper" do
  before do
    @db = Sequel.mock
    @c = Class.new(Sequel::Model(@db[:test]))
    @c.columns :name, :b
    @c.db_schema[:b][:type] = :blob
    @c.plugin :string_stripper
    @o = @c.new
  end

  it "should strip all input strings" do
    @o.name = ' name '
    @o.name.should == 'name'
  end

  it "should not affect other types" do
    @o.name = 1
    @o.name.should == 1
    @o.name = Date.today
    @o.name.should == Date.today
  end

  it "should not strip strings for blob arguments" do
    v = Sequel.blob(' name ')
    @o.name = v
    @o.name.should equal(v)
  end

  it "should not strip strings for blob columns" do
    @o.b = ' name '
    @o.b.should be_a_kind_of(Sequel::SQL::Blob)
    @o.b.should == Sequel.blob(' name ')
  end

  it "should allow skipping of columns using Model.skip_string_stripping" do
    @c.skip_string_stripping?(:name).should == false
    @c.skip_string_stripping :name
    @c.skip_string_stripping?(:name).should == true
    v = ' name '
    @o.name = v
    @o.name.should equal(v)
  end

  it "should work correctly in subclasses" do
    o = Class.new(@c).new
    o.name = ' name '
    o.name.should == 'name'
    o.b = ' name '
    o.b.should be_a_kind_of(Sequel::SQL::Blob)
    o.b.should == Sequel.blob(' name ')
  end

  it "should work correctly for dataset changes" do
    c = Class.new(Sequel::Model(@db[:test]))
    c.plugin :string_stripper
    def @db.supports_schema_parsing?() true end
    def @db.schema(*) [[:name, {}], [:b, {:type=>:blob}]] end
    c.set_dataset(@db[:test2])
    o = c.new
    o.name = ' name '
    o.name.should == 'name'
    o.b = ' name '
    o.b.should be_a_kind_of(Sequel::SQL::Blob)
    o.b.should == Sequel.blob(' name ')
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
sequel-4.22.0 spec/extensions/string_stripper_spec.rb
sequel-4.21.0 spec/extensions/string_stripper_spec.rb
sequel-4.20.0 spec/extensions/string_stripper_spec.rb
sequel-4.19.0 spec/extensions/string_stripper_spec.rb
sequel-4.18.0 spec/extensions/string_stripper_spec.rb
sequel-4.17.0 spec/extensions/string_stripper_spec.rb
sequel-4.16.0 spec/extensions/string_stripper_spec.rb
asana2flowdock-1.0.0 vendor/bundle/ruby/1.9.1/gems/sequel-4.15.0/spec/extensions/string_stripper_spec.rb
sequel-4.15.0 spec/extensions/string_stripper_spec.rb
sequel-4.14.0 spec/extensions/string_stripper_spec.rb
sequel-4.13.0 spec/extensions/string_stripper_spec.rb
sequel-4.12.0 spec/extensions/string_stripper_spec.rb
sequel-4.11.0 spec/extensions/string_stripper_spec.rb
sequel-4.10.0 spec/extensions/string_stripper_spec.rb
sequel-4.9.0 spec/extensions/string_stripper_spec.rb
sequel-4.8.0 spec/extensions/string_stripper_spec.rb
sequel-4.7.0 spec/extensions/string_stripper_spec.rb
sequel-4.6.0 spec/extensions/string_stripper_spec.rb
sequel-4.5.0 spec/extensions/string_stripper_spec.rb
sequel-4.4.0 spec/extensions/string_stripper_spec.rb