<commit_before>require 'helper'

class TestRailsRelationFix< Test::Unit::TestCase
  context "RailsRelationFix tests" do
    setup do
      @user = User.create(:name => "<NAME>") 
      @titanic = @user.movies.create(:name => "Titanic")
    end

    context "Models testing" do
      should "User has movie" do
        assert_equal(@titanic, @user.movies.first)
      end 
    
      should "Movie belongs to user" do
        assert_equal(@user, @titanic.subject)
      end 
    end
    
    context "Association bug tests" do      
      should "return empty collection after destroy its only movie" do
        @user.movies.destroy(@titanic)
        assert_equal([], @user.movies)
      end
    end
    
    context "Counter_cache for polymorhpic association bug test" do
      should "Update movies_count column after adding movie by <<" do
        @user.movies << Movie.create(:name => "Matrix")
        assert_equal(2, @user.reload.movies_count)
        @titanic.destroy
        assert_equal(1, @user.reload.movies_count)
      end
    end
  end
end<commit_msg>Add test about refreshing size<commit_after>require 'helper'

class TestRailsRelationFix< Test::Unit::TestCase
  context "RailsRelationFix tests" do
    setup do
      @user = User.create(:name => "<NAME>") 
      @titanic = @user.movies.create(:name => "Titanic")
    end

    context "Models testing" do
      should "User has movie" do
        assert_equal(@titanic, @user.movies.first)
      end 
    
      should "Movie belongs to user" do
        assert_equal(@user, @titanic.subject)
      end 
    end
    
    context "Association bug tests" do      
      should "return empty collection after destroy its only movie" do
        @user.movies.destroy(@titanic)
        assert_equal([], @user.movies)
      end
    end
    
    context "Counter_cache for polymorhpic association bug test" do
      should "Update movies_count column after adding movie by << or destroing" do
        @user.movies << Movie.create(:name => "Matrix")
        assert_equal(2, @user.reload.movies_count)
        @titanic.destroy
        assert_equal(1, @user.reload.movies_count)
      end
      
      should "Refresh size after adding movie by << or destroing" do
        @user.movies << Movie.create(:name => "Matrix")
        assert_equal(2, @user.movies.size)
        @titanic.destroy
        assert_equal(1, @user.movies.size)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09871422646204894, 'fraction_numerical': 0.002488593944421402, 'mean_word_length': 2.541850220264317, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4917078', 'n_tokens_mistral': 739, 'n_tokens_neox': 725, 'n_words': 202}