<commit_before>
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe ActiveRecord::Base do

  after(:each) do
    remove_all_models
  end

  context "in basic case" do
    before(:each) do
      create_tables(
        "posts", {}, {},
        "comments", {}, { :post_id => {} }
      )
      class Post < ActiveRecord::Base ; end
      class Comment < ActiveRecord::Base ; end
    end

    it "should create belongs_to association when reflecting on it" do
      reflection = Comment.reflect_on_association(:post)
      reflection.should_not be_nil
      reflection.macro.should == :belongs_to
      reflection.options[:class_name].should == "Post"
      reflection.options[:foreign_key].should == "post_id"
      reflection.options[:inverse_of].should == :comments
    end

    it "should create association when reflecting on all associations" do
      reflection = Comment.reflect_on_all_associations.first
      reflection.should_not be_nil
      reflection.macro.should == :belongs_to
      reflection.options[:class_name].should == "Post"
      reflection.options[:foreign_key].should == "post_id"
      reflection.options[:inverse_of].should == :comments
    end

    it "should create association when accessing it" do
      post = Post.create
      comment = Comment.create(:post_id => post.id)
      comment.post.id.should == post.id
    end

    it "should create association when creating record" do
      post = Post.create
      comment = Comment.create(:post => post)
      comment.reload.post.id.should == post.id
    end<commit_msg>add accepts_nested_attributes_for spec<commit_after>
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe ActiveRecord::Base do

  after(:each) do
    remove_all_models
  end

  context "in basic case" do
    before(:each) do
      create_tables(
        "posts", {}, {},
        "comments", {}, { :post_id => {} }
      )
      class Post < ActiveRecord::Base ; end
      class Comment < ActiveRecord::Base ; end
    end

    it "should create belongs_to association when reflecting on it" do
      reflection = Comment.reflect_on_association(:post)
      reflection.should_not be_nil
      reflection.macro.should == :belongs_to
      reflection.options[:class_name].should == "Post"
      reflection.options[:foreign_key].should == "post_id"
      reflection.options[:inverse_of].should == :comments
    end

    it "should create association when reflecting on all associations" do
      reflection = Comment.reflect_on_all_associations.first
      reflection.should_not be_nil
      reflection.macro.should == :belongs_to
      reflection.options[:class_name].should == "Post"
      reflection.options[:foreign_key].should == "post_id"
      reflection.options[:inverse_of].should == :comments
    end

    it "should create association when accepts_nested_attributes_for is called" do
      expect {
        Post.class_eval { accepts_nested_attributes_for :comments }
      }.to_not raise_error
    end

    it "should create association when accessing it" do
      post = Post.create
      comment = Comment.create(:post_id => post.id)
      comment.post.id.should == post.id
    end

    it "should create association when creating record" do
      post = Post.create
      comment = Comment.create(:post => post)
      comment.reload.post.id.should == post.id
    end
{'fraction_non_alphanumeric': 0.10175022248590923, 'fraction_numerical': 0.0, 'mean_word_length': 3.127294981640147, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '7024801', 'n_tokens_mistral': 954, 'n_tokens_neox': 943, 'n_words': 235}