Skip to content

Rails4 #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.gem
.bundle
Gemfile.lock
.idea
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source :rubygems
source 'https://rubygems.org'

gemspec
2 changes: 1 addition & 1 deletion activerecord-postgres-array.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |s|
s.rubygems_version = %q{1.3.7}
s.summary = s.description

s.add_dependency "activerecord"
s.add_dependency "activerecord", '~> 4.0.0'
s.add_development_dependency 'rake'
s.add_development_dependency 'rspec', '~> 2.12.0'
s.add_development_dependency 'pg'
Expand Down
6 changes: 3 additions & 3 deletions lib/activerecord-postgres-array/activerecord.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def native_database_types_with_array(*args)

# Quotes a value for use in an SQL statement
def quote_with_array(value, column = nil)
if value && column && column.sql_type =~ /\[\]$/
if value && column && column.type =~ /\[\]$/
raise ArrayTypeMismatch, "#{column.name} must be an Array or have a valid array value (#{value})" unless value.kind_of?(Array) || value.valid_postgres_array?
return value.to_postgres_array
end
Expand All @@ -59,7 +59,7 @@ class Table
PostgreSQLAdapter::POSTGRES_ARRAY_TYPES.each do |column_type|
define_method("#{column_type}_array") do |*args|
options = args.extract_options!
base_type = @base.type_to_sql(column_type.to_sym, options[:limit], options[:precision], options[:scale])
base_type = ActiveRecord::Base.connection.type_to_sql(column_type.to_sym, options[:limit], options[:precision], options[:scale])
column_names = args
column_names.each { |name| column(name, "#{base_type}[]", options) }
end
Expand All @@ -77,7 +77,7 @@ class TableDefinition
PostgreSQLAdapter::POSTGRES_ARRAY_TYPES.each do |column_type|
define_method("#{column_type}_array") do |*args|
options = args.extract_options!
base_type = @base.type_to_sql(column_type.to_sym, options[:limit], options[:precision], options[:scale])
base_type = ActiveRecord::Base.connection.type_to_sql(column_type.to_sym, options[:limit], options[:precision], options[:scale])
column_names = args
column_names.each { |name| column(name, "#{base_type}[]", options) }
end
Expand Down
6 changes: 3 additions & 3 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
it "escapes single quotes correctly" do
article = Article.create(:languages => ["English", "Ger'man"])
article.reload
article.languages_before_type_cast.should == "{English,Ger''man}"
article.languages_before_type_cast.should == "{English,Ger'man}"
article.languages.should == ["English", "Ger'man"]
end

Expand All @@ -33,7 +33,7 @@
end

it "handles backslashes correctly" do
article = Article.create(:languages => ["\\","\""])
article = Article.create(:languages => ["\\\\","\""])
article.reload
article.languages_before_type_cast.should == '{"\\\\","\\""}'
article.languages.should == ["\\","\""]
Expand Down Expand Up @@ -112,7 +112,7 @@
end

it "handles backslashes correctly" do
@article.languages = ["\\","\""]
@article.languages = ["\\\\","\""]
@article.save
@article.reload
@article.languages_before_type_cast.should == '{"\\\\","\\""}'
Expand Down