class AssociationProxyTest
Public Instance Methods
test_append_behaves_like_push()
click to toggle source
# File activerecord/test/cases/associations_test.rb, line 151 def test_append_behaves_like_push josh = Author.new(name: "Josh") josh.posts.append Post.new(title: "New on Edge", body: "More cool stuff!") assert josh.posts.loaded? assert_equal 1, josh.posts.size end
test_create_via_association_with_block()
click to toggle source
# File activerecord/test/cases/associations_test.rb, line 190 def test_create_via_association_with_block post = authors(:david).posts.create(title: "New on Edge") { |p| p.body = "More cool stuff!" } assert_equal post.title, "New on Edge" assert_equal post.body, "More cool stuff!" end
test_create_with_bang_via_association_with_block()
click to toggle source
# File activerecord/test/cases/associations_test.rb, line 196 def test_create_with_bang_via_association_with_block post = authors(:david).posts.create!(title: "New on Edge") { |p| p.body = "More cool stuff!" } assert_equal post.title, "New on Edge" assert_equal post.body, "More cool stuff!" end
test_inspect_does_not_reload_a_not_yet_loaded_target()
click to toggle source
# File activerecord/test/cases/associations_test.rb, line 179 def test_inspect_does_not_reload_a_not_yet_loaded_target andreas = Developer.new name: "Andreas", log: "new developer added" assert !andreas.audit_logs.loaded? assert_match(/message: "new developer added"/, andreas.audit_logs.inspect) end
test_load_does_load_target()
click to toggle source
# File activerecord/test/cases/associations_test.rb, line 171 def test_load_does_load_target david = developers(:david) assert !david.projects.loaded? david.projects.load assert david.projects.loaded? end
test_pluck_uses_loaded_target()
click to toggle source
# File activerecord/test/cases/associations_test.rb, line 255 def test_pluck_uses_loaded_target david = authors(:david) assert_equal david.first_posts.pluck(:title), david.first_posts.load.pluck(:title) assert david.first_posts.loaded? assert_no_queries { david.first_posts.pluck(:title) } end
test_prepend_is_not_defined()
click to toggle source
# File activerecord/test/cases/associations_test.rb, line 158 def test_prepend_is_not_defined josh = Author.new(name: "Josh") assert_raises(NoMethodError) { josh.posts.prepend Post.new } end
test_proxy_association_accessor()
click to toggle source
# File activerecord/test/cases/associations_test.rb, line 209 def test_proxy_association_accessor david = developers(:david) assert_equal david.association(:projects), david.projects.proxy_association end
test_push_does_not_load_target()
click to toggle source
# File activerecord/test/cases/associations_test.rb, line 118 def test_push_does_not_load_target david = authors(:david) david.posts << (post = Post.new(title: "New on Edge", body: "More cool stuff!")) assert !david.posts.loaded? assert_includes david.posts, post end
test_push_does_not_lose_additions_to_new_record()
click to toggle source
# File activerecord/test/cases/associations_test.rb, line 144 def test_push_does_not_lose_additions_to_new_record josh = Author.new(name: "Josh") josh.posts << Post.new(title: "New on Edge", body: "More cool stuff!") assert josh.posts.loaded? assert_equal 1, josh.posts.size end
test_push_followed_by_save_does_not_load_target()
click to toggle source
# File activerecord/test/cases/associations_test.rb, line 134 def test_push_followed_by_save_does_not_load_target david = authors(:david) david.posts << (post = Post.new(title: "New on Edge", body: "More cool stuff!")) assert !david.posts.loaded? david.save assert !david.posts.loaded? assert_includes david.posts, post end
test_push_has_many_through_does_not_load_target()
click to toggle source
# File activerecord/test/cases/associations_test.rb, line 126 def test_push_has_many_through_does_not_load_target david = authors(:david) david.categories << categories(:technology) assert !david.categories.loaded? assert_includes david.categories, categories(:technology) end
test_reload_returns_association()
click to toggle source
# File activerecord/test/cases/associations_test.rb, line 202 def test_reload_returns_association david = developers(:david) assert_nothing_raised do assert_equal david.projects, david.projects.reload.reload end end
test_reset_unloads_target()
click to toggle source
# File activerecord/test/cases/associations_test.rb, line 262 def test_reset_unloads_target david = authors(:david) david.posts.reload assert david.posts.loaded? david.posts.reset assert !david.posts.loaded? end
test_save_on_parent_does_not_load_target()
click to toggle source
# File activerecord/test/cases/associations_test.rb, line 163 def test_save_on_parent_does_not_load_target david = developers(:david) assert !david.projects.loaded? david.update_columns(created_at: Time.now) assert !david.projects.loaded? end
test_save_on_parent_saves_children()
click to toggle source
# File activerecord/test/cases/associations_test.rb, line 185 def test_save_on_parent_saves_children developer = Developer.create name: "Bryan", salary: 50_000 assert_equal 1, developer.reload.audit_logs.size end
test_scoped_allows_conditions()
click to toggle source
# File activerecord/test/cases/associations_test.rb, line 214 def test_scoped_allows_conditions assert developers(:david).projects.merge(where: "foo").to_sql.include?("foo") end