Skip to content

Instantly share code, notes, and snippets.

@senny
Created September 27, 2013 07:51
Show Gist options
  • Save senny/6725398 to your computer and use it in GitHub Desktop.
Save senny/6725398 to your computer and use it in GitHub Desktop.
require 'bundler'
Bundler.setup(:default)
require 'active_record'
require 'minitest/autorun'
require 'logger'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'postgresql', database: 'rails_bug')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
drop_table "posts"
create_table :posts do |t|
t.string :tags, array: true
end
end
class Post < ActiveRecord::Base
has_many :comments
end
class BugTest < Minitest::Test
def test_array_stuff
post = Post.create!(tags: ["one", "two", "three"])
post.update_column(:tags, ["four", "five"])
assert_equal ["four", "five"], Post.first.tags
end
end
@senny
Copy link
Author

senny commented Sep 27, 2013

This fails with (tested against rails/rails@7045a5b ):

  1) Error:
BugTest#test_array_stuff:
ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR:  syntax error at or near "'five'"
LINE 1: UPDATE "posts" SET "tags" = 'four','five' WHERE "posts"."id"...
                                           ^
: UPDATE "posts" SET "tags" = 'four','five' WHERE "posts"."id" = 1
    /Users/senny/Projects/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:775:in `exec'
    /Users/senny/Projects/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:775:in `exec_no_cache'
    /Users/senny/Projects/rails/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb:160:in `block in exec_delete'
    /Users/senny/Projects/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:432:in `block in log'
    /Users/senny/Projects/rails/activesupport/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    /Users/senny/Projects/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:427:in `log'
    /Users/senny/Projects/rails/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb:159:in `exec_delete'
    /Users/senny/Projects/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:100:in `update'
    /Users/senny/Projects/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `update'
    /Users/senny/Projects/rails/activerecord/lib/active_record/relation.rb:321:in `update_all'
    /Users/senny/Projects/rails/activerecord/lib/active_record/persistence.rb:276:in `update_columns'
    /Users/senny/Projects/rails/activerecord/lib/active_record/persistence.rb:251:in `update_column'
    bug.rb:26:in `test_array_stuff'

@senny
Copy link
Author

senny commented Feb 10, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment