Class: EnsuresImmutabilityOfTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- EnsuresImmutabilityOfTest
- Defined in:
- lib/immutable-attribute-plugin/test/unit/plugin_test.rb
Instance Method Summary collapse
- #test_assignment_if_nil ⇒ Object
- #test_association_assignment_if_nil ⇒ Object
- #test_belong_id_readonly ⇒ Object
- #test_error_on_assignment ⇒ Object
- #test_error_on_association_assignment ⇒ Object
- #test_error_on_association_update ⇒ Object
- #test_error_on_belong_assignment ⇒ Object
- #test_error_on_update ⇒ Object
- #test_overrides_all_setters_when_configured_with_all_symbol ⇒ Object
- #test_protected_has_many_assignment ⇒ Object
- #test_set_on_creation ⇒ Object
- #test_set_same ⇒ Object
Instance Method Details
#test_assignment_if_nil ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/immutable-attribute-plugin/test/unit/plugin_test.rb', line 95 def test_assignment_if_nil account = accounts(:nil_account) assert_nothing_thrown do account.username = 'jgreen' end assert account.save end |
#test_association_assignment_if_nil ⇒ Object
16 17 18 19 20 21 |
# File 'lib/immutable-attribute-plugin/test/unit/plugin_test.rb', line 16 def test_association_assignment_if_nil account = accounts(:nil_account) assert_nothing_thrown do account.info = infos(:foo) end end |
#test_belong_id_readonly ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/immutable-attribute-plugin/test/unit/plugin_test.rb', line 54 def test_belong_id_readonly zee_info = ProtectedInfo.create :text => "zee" wmoxam_account = accounts(:wmoxam) assert_nothing_raised do zee_info.account = wmoxam_account end nil_account = accounts(:nil_account) zee_info.account_id = nil_account.id assert_not_equal zee_info.account_id, wmoxam_account.id, "Failed to forcefully set the id." zee_info.save! assert_equal zee_info.account_id, wmoxam_account.id, "The reload did not reset the id to correct id." end |
#test_error_on_assignment ⇒ Object
124 125 126 127 128 129 |
# File 'lib/immutable-attribute-plugin/test/unit/plugin_test.rb', line 124 def test_error_on_assignment account = accounts(:wmoxam) assert_raise ActiveRecord::ImmutableAttributeError do account.username = 'jgreen' end end |
#test_error_on_association_assignment ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/immutable-attribute-plugin/test/unit/plugin_test.rb', line 23 def test_error_on_association_assignment account = accounts(:wmoxam) account.info = infos(:foo) assert_raise ActiveRecord::ImmutableAttributeError do account.info = infos(:bar) end end |
#test_error_on_association_update ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/immutable-attribute-plugin/test/unit/plugin_test.rb', line 32 def test_error_on_association_update account = accounts(:wmoxam) assert account.info.nil? account.info = infos(:foo) assert_raise ActiveRecord::ImmutableAttributeError do account.update_attributes(:info => infos(:bar)) end end |
#test_error_on_belong_assignment ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/immutable-attribute-plugin/test/unit/plugin_test.rb', line 42 def test_error_on_belong_assignment zee_info = ProtectedInfo.create :text => "zee" assert_nothing_raised do zee_info.account = accounts(:wmoxam) end assert_raise ActiveRecord::ImmutableAttributeError do zee_info.account = accounts(:nil_account) end end |
#test_error_on_update ⇒ Object
131 132 133 134 135 136 |
# File 'lib/immutable-attribute-plugin/test/unit/plugin_test.rb', line 131 def test_error_on_update account = accounts(:wmoxam) assert_raise ActiveRecord::ImmutableAttributeError do account.update_attributes(:username => 'jgreen') end end |
#test_overrides_all_setters_when_configured_with_all_symbol ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/immutable-attribute-plugin/test/unit/plugin_test.rb', line 103 def test_overrides_all_setters_when_configured_with_all_symbol account = ImmutableAccount.create({ :username => 'johndoe', :email => '[email protected]', :info => infos(:foo), :infos => [infos(:bar)] }) assert_raise ActiveRecord::ImmutableAttributeError do account.username = 'janedoe' end assert_raise ActiveRecord::ImmutableAttributeError do account.email = '[email protected]' end assert_raise ActiveRecord::ImmutableAttributeError do account.info = infos(:bar) end assert_raise ActiveRecord::ImmutableAttributeError do account.infos = [infos(:foo)] end end |
#test_protected_has_many_assignment ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/immutable-attribute-plugin/test/unit/plugin_test.rb', line 70 def test_protected_has_many_assignment account = accounts(:nil_account) assert account.infos.empty?, "Account infos should be empty" account.infos = [infos(:bar)] assert_raise ActiveRecord::ImmutableAttributeError do account.infos = [infos(:foo)] end end |
#test_set_on_creation ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/immutable-attribute-plugin/test/unit/plugin_test.rb', line 79 def test_set_on_creation account = nil assert_nothing_thrown do account = Account.create(:username => 'jgreen') end assert account.valid? assert account.username == 'jgreen' end |
#test_set_same ⇒ Object
88 89 90 91 92 93 |
# File 'lib/immutable-attribute-plugin/test/unit/plugin_test.rb', line 88 def test_set_same account = accounts(:wmoxam) assert_nothing_thrown do account.username = 'wmoxam' end end |