Sha256: 1a8a9705cd6f115d218c7c03654873478fd694615e730f5dfbb92b3546b311bb

Contents?: true

Size: 1.33 KB

Versions: 23

Compression:

Stored size: 1.33 KB

Contents

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

describe "prepared_statements_with_pk plugin" do
  before do
    @db = Sequel.mock(:fetch=>{:id=>1, :name=>'foo', :i=>2}, :autoid=>proc{|sql| 1}, :numrows=>1, :servers=>{:read_only=>{}})
    @c = Class.new(Sequel::Model(@db[:people]))
    @c.columns :id, :name, :i
    @c.plugin :prepared_statements_with_pk
    @p = @c.load(:id=>1, :name=>'foo', :i=>2)
    @db.sqls
  end

  it "should load the prepared_statements plugin" do
    @c.plugins.must_include(Sequel::Plugins::PreparedStatements)
  end

  it "should correctly lookup by primary key from dataset" do
    @c.dataset.filter(:name=>'foo')[1].must_equal @p
    @c.db.sqls.must_equal ["SELECT * FROM people WHERE ((name = 'foo') AND (people.id = 1)) LIMIT 1 -- read_only"]
  end

  it "should still work correctly if there are multiple conflicting variables" do
    @c.dataset.filter(:name=>'foo').or(:name=>'bar')[1].must_equal @p
    @c.db.sqls.must_equal ["SELECT * FROM people WHERE (((name = 'foo') OR (name = 'bar')) AND (people.id = 1)) LIMIT 1 -- read_only"]
  end

  it "should still work correctly if the primary key is used elsewhere in the query" do
    @c.dataset.filter{id > 2}[1].must_equal @p
    @c.db.sqls.must_equal ["SELECT * FROM people WHERE ((id > 2) AND (people.id = 1)) LIMIT 1 -- read_only"]
  end
end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
sequel-4.42.1 spec/extensions/prepared_statements_with_pk_spec.rb
sequel-4.42.0 spec/extensions/prepared_statements_with_pk_spec.rb
sequel-4.41.0 spec/extensions/prepared_statements_with_pk_spec.rb
sequel-4.40.0 spec/extensions/prepared_statements_with_pk_spec.rb
sequel-4.39.0 spec/extensions/prepared_statements_with_pk_spec.rb
tdiary-5.0.2 vendor/bundle/gems/sequel-4.37.0/spec/extensions/prepared_statements_with_pk_spec.rb
sequel-4.38.0 spec/extensions/prepared_statements_with_pk_spec.rb
sequel-4.37.0 spec/extensions/prepared_statements_with_pk_spec.rb
sequel-4.36.0 spec/extensions/prepared_statements_with_pk_spec.rb
tdiary-5.0.1 vendor/bundle/gems/sequel-4.35.0/spec/extensions/prepared_statements_with_pk_spec.rb
sequel-4.35.0 spec/extensions/prepared_statements_with_pk_spec.rb
sequel-4.34.0 spec/extensions/prepared_statements_with_pk_spec.rb
sequel-4.33.0 spec/extensions/prepared_statements_with_pk_spec.rb
sequel-4.32.0 spec/extensions/prepared_statements_with_pk_spec.rb
sequel-4.31.0 spec/extensions/prepared_statements_with_pk_spec.rb
sequel-4.30.0 spec/extensions/prepared_statements_with_pk_spec.rb
sequel-4.29.0 spec/extensions/prepared_statements_with_pk_spec.rb
sequel-4.28.0 spec/extensions/prepared_statements_with_pk_spec.rb
sequel-4.27.0 spec/extensions/prepared_statements_with_pk_spec.rb
sequel-4.26.0 spec/extensions/prepared_statements_with_pk_spec.rb