diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-06-13 11:03:03 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-06-13 11:13:36 +0900 |
commit | d690af13fcdae086b08dc0043643f5a66ea8cb06 (patch) | |
tree | bdecfacc878e90829c20401d805a2485930c3435 /activerecord/test/cases | |
parent | ceaf455c923a9f04c9ac4e92cd23360caf3a2acf (diff) | |
parent | e0bc5b4da1882a722975b920ec912d6229a8f92e (diff) | |
download | rails-d690af13fcdae086b08dc0043643f5a66ea8cb06.tar.gz rails-d690af13fcdae086b08dc0043643f5a66ea8cb06.tar.bz2 rails-d690af13fcdae086b08dc0043643f5a66ea8cb06.zip |
Merge pull request #29373 from untidy-hair/store_accessor_enhance
Allow prefix/suffix options for store accessors
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/store_test.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/activerecord/test/cases/store_test.rb b/activerecord/test/cases/store_test.rb index 3bd480cfbd..4457cfbd37 100644 --- a/activerecord/test/cases/store_test.rb +++ b/activerecord/test/cases/store_test.rb @@ -214,4 +214,38 @@ class StoreTest < ActiveRecord::TestCase second_dump = YAML.dump(loaded) assert_equal @john, YAML.load(second_dump) end + + test "read store attributes through accessors with default suffix" do + @john.configs[:two_factor_auth] = true + assert_equal true, @john.two_factor_auth_configs + end + + test "write store attributes through accessors with default suffix" do + @john.two_factor_auth_configs = false + assert_equal false, @john.configs[:two_factor_auth] + end + + test "read store attributes through accessors with custom suffix" do + @john.configs[:login_retry] = 3 + assert_equal 3, @john.login_retry_config + end + + test "write store attributes through accessors with custom suffix" do + @john.login_retry_config = 5 + assert_equal 5, @john.configs[:login_retry] + end + + test "read accessor without pre/suffix in the same store as other pre/suffixed accessors still works" do + @john.configs[:secret_question] = "What is your high school?" + assert_equal "What is your high school?", @john.secret_question + end + + test "write accessor without pre/suffix in the same store as other pre/suffixed accessors still works" do + @john.secret_question = "What was the Rails version when you first worked on it?" + assert_equal "What was the Rails version when you first worked on it?", @john.configs[:secret_question] + end + + test "prefix/suffix do not affect stored attributes" do + assert_equal [:secret_question, :two_factor_auth, :login_retry], Admin::User.stored_attributes[:configs] + end end |