Ticket #11393: associations_respects_hash_conditions.diff
| File associations_respects_hash_conditions.diff, 3.1 kB (added by miloops, 2 years ago) |
|---|
-
test/models/category.rb
old new 9 9 :association_foreign_key => 'post_id', 10 10 :select => 'posts.*, 1 as correctness_marker') 11 11 12 has_and_belongs_to_many :post_with_conditions, 13 :class_name => 'Post', 14 :conditions => { :title => 'Yet Another Testing Title' } 12 15 def self.what_are_you 13 16 'a category...' 14 17 end -
test/cases/associations_test.rb
old new 1014 1014 assert_equal 1, Client.find_all_by_client_of(firm.id).size 1015 1015 end 1016 1016 1017 def test_creation_respects_hash_condition 1018 ms_client = companies(:first_firm).clients_like_ms_with_hash_conditions.build 1019 1020 assert ms_client.save 1021 assert_equal 'Microsoft', ms_client.name 1022 1023 another_ms_client = companies(:first_firm).clients_like_ms_with_hash_conditions.create 1024 1025 assert !another_ms_client.new_record? 1026 assert_equal 'Microsoft', another_ms_client.name 1027 end 1028 1017 1029 def test_dependent_delete_and_destroy_with_belongs_to 1018 1030 author_address = author_addresses(:david_address) 1019 1031 assert_equal [], AuthorAddress.destroyed_author_address_ids[authors(:david).id] … … 1826 1838 assert_equal Developer.find_by_name("Marcel").projects.last, proj2 # prove join table is updated 1827 1839 end 1828 1840 1841 def test_creation_respects_hash_condition 1842 post = categories(:general).post_with_conditions.build(:body => '') 1843 1844 assert post.save 1845 assert_equal 'Yet Another Testing Title', post.title 1846 1847 another_post = categories(:general).post_with_conditions.create(:body => '') 1848 1849 assert !another_post.new_record? 1850 assert_equal 'Yet Another Testing Title', another_post.title 1851 end 1852 1829 1853 def test_uniq_after_the_fact 1830 1854 developers(:jamis).projects << projects(:active_record) 1831 1855 developers(:jamis).projects << projects(:active_record) -
lib/active_record/associations/association_collection.rb
old new 202 202 private 203 203 204 204 def create_record(attrs) 205 attrs.update(@reflection.options[:conditions]) if @reflection.options[:conditions].is_a?(Hash) 205 206 ensure_owner_is_not_new 206 207 record = @reflection.klass.send(:with_scope, :create => construct_scope[:create]) { @reflection.klass.new(attrs) } 207 208 if block_given? … … 212 213 end 213 214 214 215 def build_record(attrs) 216 attrs.update(@reflection.options[:conditions]) if @reflection.options[:conditions].is_a?(Hash) 215 217 record = @reflection.klass.new(attrs) 216 218 if block_given? 217 219 add_record_to_target_with_callbacks(record) { |*block_args| yield(*block_args) }