Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes #<attribute_name>?, Adds (pending) test case for #update_column

  • Loading branch information...
commit dbdabd6f348ef093d88b1b3e6e0f0ff86d350272 1 parent 483a823
@danmcclain danmcclain authored
View
5 lib/postgres_ext/active_record/connection_adapters/postgres_adapter.rb
@@ -67,6 +67,10 @@ def type_cast_array(array)
end
end
+ def number?
+ !self.array && super
+ end
+
def type_cast_code_with_extended_types(var_name)
klass = self.class.name
@@ -88,6 +92,7 @@ def string_to_cidr_address(string)
return IPAddr.new(string)
end
end
+
private
def force_character_encoding(string_array)
View
39 spec/models/array_spec.rb
@@ -7,12 +7,13 @@
before do
adapter.create_table :users, :force => true do |t|
t.string :nick_names, :array => true
+ t.integer :favorite_numbers, :array => true
t.timestamps
end
class User < ActiveRecord::Base
- attr_accessible :nick_names
+ attr_accessible :nick_names, :favorite_numbers
end
end
@@ -73,6 +74,42 @@ class User < ActiveRecord::Base
end
end
+ context '#<column>? do' do
+ describe 'checking a value via <attribute_name>? 'do
+ it 'returns false if it\'s an empty array' do
+ user = User.create(:nick_names => [], :favorite_numbers => [])
+ user.reload
+
+ user.nick_names?.should be_false
+ user.favorite_numbers?.should be_false
+ end
+
+ it 'returns false if it\'s an empty array' do
+ user = User.create(:nick_names => ['bob'], :favorite_numbers => [0])
+ user.reload
+
+ user.nick_names?.should be_true
+ user.favorite_numbers?.should be_true
+ end
+ end
+ end
+
+ context '#update_column' do
+ describe 'setting a value via update_column' do
+ it 'returns the value set when the record is retrieved' do
+ pending #This fails, not sure where to fix this, takes different code path than #update_attribute
+ user = User.create(:nick_names => [])
+ user.reload
+
+ user.update_column(:nick_names, ['some', 'values'])
+ user.save
+
+ user.reload
+ user.nick_names.should eq ['some', 'values']
+ end
+ end
+ end
+
context '#update_attributes' do
describe 'setting a value via update_attributes' do
it 'returns the value set when the record is retrieved' do
Please sign in to comment.
Something went wrong with that request. Please try again.