spec/extensions/prepared_statements_spec.rb in sequel-4.41.0 vs spec/extensions/prepared_statements_spec.rb in sequel-4.42.0

- old
+ new

@@ -47,11 +47,11 @@ end def supports_returning?(type) true end def insert_select(h) - self._fetch = {:id=>1, :name=>'foo', :i => 2} + cache_set(:_fetch, :id=>1, :name=>'foo', :i => 2) server(:default).with_sql_first(insert_select_sql(h)) end def insert_select_sql(*v) "#{insert_sql(*v)} RETURNING #{(opts[:returning] && !opts[:returning].empty?) ? opts[:returning].map{|c| literal(c)}.join(', ') : '*'}" end @@ -78,30 +78,31 @@ @db.sqls.must_equal ["SELECT id, name, i FROM people WHERE (id = 1) LIMIT 1 -- read_only"] end describe " with placeholder type specifiers" do before do - @ds.meta_def(:requires_placeholder_type_specifiers?){true} + @ds = @ds.with_extend{def requires_placeholder_type_specifiers?; true end} end it "should correctly handle without schema type" do @c[1].must_equal @p @db.sqls.must_equal ["SELECT id, name, i FROM people WHERE (id = 1) LIMIT 1 -- read_only"] end it "should correctly handle with schema type" do @c.db_schema[:id][:type] = :integer - ds = @c.send(:prepared_lookup) - def ds.literal_symbol_append(sql, v) - if @opts[:bind_vars] and match = /\A\$(.*)\z/.match(v.to_s) - s = match[1].split('__')[0].to_sym - if prepared_arg?(s) - literal_append(sql, prepared_arg(s)) + ds = @c.send(:prepared_lookup).with_extend do + def literal_symbol_append(sql, v) + if @opts[:bind_vars] and match = /\A\$(.*)\z/.match(v.to_s) + s = match[1].split('__')[0].to_sym + if prepared_arg?(s) + literal_append(sql, prepared_arg(s)) + else + sql << v.to_s + end else - sql << v.to_s + super end - else - super end end @c[1].must_equal @p @db.sqls.must_equal ["SELECT id, name, i FROM people WHERE (id = 1) LIMIT 1 -- read_only"] end