Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow store to be a not null column. #4856

Merged
merged 1 commit into from

2 participants

@iHiD

Pull request to fix issue #4840 (cc @tenderlove)

I don't really like the fact it's checking the variable every time the column is accessed, but unless we want to play around with the initialisation of the variable, it seems to be the most robust way.

@tenderlove tenderlove merged commit 2abaa19 into rails:master
@yahonda yahonda referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@yahonda yahonda referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@yahonda yahonda referenced this pull request from a commit in yahonda/rails
@yahonda yahonda Modify the preference attribute from `:null => false` to `:null => true`
to address ORA-01400 errors with Oracle enhanced adapter.

Issue #4856 had been fixed and tested with
the attribute `:null => false, :default => ""`.
Now `:null => false` attribute is not necessary to test this issue.
dab8ca5
@iHiD iHiD referenced this pull request from a commit in iHiD/rails
@iHiD iHiD Ported PR #4856 to 3-2-stable. 2a6039a
@lmars lmars referenced this pull request from a commit in econsultancy/rails
@iHiD iHiD Ported PR #4856 to 3-2-stable. 39b7036
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 2, 2012
  1. @iHiD
This page is out of date. Refresh to see the latest.
View
2  activerecord/lib/active_record/store.rb
@@ -36,11 +36,13 @@ def store(store_attribute, options = {})
def store_accessor(store_attribute, *keys)
Array(keys).flatten.each do |key|
define_method("#{key}=") do |value|
+ send("#{store_attribute}=", {}) unless send(store_attribute).is_a?(Hash)
send(store_attribute)[key] = value
send("#{store_attribute}_will_change!")
end
define_method(key) do
+ send("#{store_attribute}=", {}) unless send(store_attribute).is_a?(Hash)
send(store_attribute)[key]
end
end
View
13 activerecord/test/cases/store_test.rb
@@ -4,14 +4,14 @@
class StoreTest < ActiveRecord::TestCase
setup do
- @john = Admin::User.create(:name => 'John Doe', :color => 'black')
+ @john = Admin::User.create(:name => 'John Doe', :color => 'black', :remember_login => true)
end
test "reading store attributes through accessors" do
assert_equal 'black', @john.color
assert_nil @john.homepage
end
-
+
test "writing store attributes through accessors" do
@john.color = 'red'
@john.homepage = '37signals.com'
@@ -31,4 +31,13 @@ class StoreTest < ActiveRecord::TestCase
@john.color = 'red'
assert @john.settings_changed?
end
+
+ test "object initialization with not nullable column" do
+ assert_equal true, @john.remember_login
+ end
+
+ test "writing with not nullable column" do
+ @john.remember_login = false
+ assert_equal false, @john.remember_login
+ end
end
View
1  activerecord/test/models/admin/user.rb
@@ -1,4 +1,5 @@
class Admin::User < ActiveRecord::Base
belongs_to :account
store :settings, :accessors => [ :color, :homepage ]
+ store :preferences, :accessors => [ :remember_login ]
end
View
3  activerecord/test/schema/schema.rb
@@ -37,7 +37,8 @@ def create_table(*args, &block)
create_table :admin_users, :force => true do |t|
t.string :name
- t.text :settings
+ t.text :settings, :null => true
+ t.text :preferences, :null => false, :default => ""
t.references :account
end
Something went wrong with that request. Please try again.