<commit_before>require "spec_helper"

describe MadCart::Store::Base do
  before(:each) do
    clear_config
    Object.send(:remove_const, :MyModel) if Object.const_defined?(:MyModel)
    class MyModel
      include MadCart::Model::Base
      required_attributes :name, :description
    end
  end

  describe "attributes" do
    it "can be configured to include additional attributes" do
      MadCart.configure do |config|
        config.include_attributes :my_models => [:external_id, :url]
      end
      
      o = MyModel.new(:name => 'whiskey', :description => 'tasty', :external_id => 2, :url => 'path/to/whiskey', :discarded => 'property')
      o.attributes.should == {"name" => 'whiskey', "description" => 'tasty', "external_id" => 2, "url" => 'path/to/whiskey'}
    end
    
    it "includes mapped attributes" do
      MadCart.configure do |config|
        config.attribute_map :my_models, :old_name => :new_name
      end
      
      o = MyModel.new(:name => 'whiskey', :description => 'tasty', :discarded => 'property', :old_name => 'is included')
      o.attributes.should == {"name" => 'whiskey', "description" => 'tasty', "new_name" => 'is included'}
    end
  end

end<commit_msg>addes a spec for mapping multiple sources to the same model<commit_after>require "spec_helper"

describe MadCart::Store::Base do
  before(:each) do
    clear_config
    Object.send(:remove_const, :MyModel) if Object.const_defined?(:MyModel)
    class MyModel
      include MadCart::Model::Base
      required_attributes :name, :description
    end
  end

  describe "attributes" do
    it "can be configured to include additional attributes" do
      MadCart.configure do |config|
        config.include_attributes :my_models => [:external_id, :url]
      end
      
      o = MyModel.new(:name => 'whiskey', :description => 'tasty', :external_id => 2, :url => 'path/to/whiskey', :discarded => 'property')
      o.attributes.should == {"name" => 'whiskey', "description" => 'tasty', "external_id" => 2, "url" => 'path/to/whiskey'}
    end
    
    it "includes mapped attributes" do
      MadCart.configure do |config|
        config.attribute_map :my_models, :old_name => :new_name
      end
      
      o = MyModel.new(:name => 'whiskey', :description => 'tasty', :discarded => 'property', :old_name => 'is included')
      o.attributes.should == {"name" => 'whiskey', "description" => 'tasty', "new_name" => 'is included'}
    end
    
    it "allows two sources to map to the same model" do
      MadCart.configure do |config|
        config.include_attributes :my_models => [:new_name]
        config.attribute_map :my_models, :old_name => :new_name
      end
      
      source_a = {:name => 'whiskey', :description => 'tasty', :discarded => 'property', :old_name => 'has been renamed'}
      source_b = {:name => 'whiskey', :description => 'tasty', :discarded => 'property', :new_name => 'is included'}
      
      model_a = MyModel.new(source_a)
      model_a.attributes.should == {"name" => 'whiskey', "description" => 'tasty', "new_name" => 'has been renamed'}
      
      model_b = MyModel.new(source_b)
      model_b.attributes.should == {"name" => 'whiskey', "description" => 'tasty', "new_name" => 'is included'}
    end
  end

end
{'fraction_non_alphanumeric': 0.14932266009852216, 'fraction_numerical': 0.0012315270935960591, 'mean_word_length': 3.3493975903614457, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 55, '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': '636370', 'n_tokens_mistral': 1037, 'n_tokens_neox': 1019, 'n_words': 266}