<commit_before>require 'spec_helper'

describe Associates do

  include_context "associates_setup"

  let(:guest_order) { GuestOrder.new }

  describe :ClassMethods do

    describe :associate do

      context "with valid arguments" do

        describe "undefined model name", :skip do
          # @TODO Think wether it is a feature or not
          # Could be metadefined later
          it { expect { GuestOrder.send(:associate, :undefined) }.not_to raise_error }
        end
<commit_msg>Add specs for #associate options<commit_after>require 'spec_helper'

describe Associates do

  include_context "associates_setup"

  let(:guest_order) { GuestOrder.new }

  describe :ClassMethods do

    describe :associate do

      context "with valid arguments" do

        describe "with options" do

          describe :only do
            before do
              GuestOrder.reset_associate!(:user)
              GuestOrder.associate(:user, only: :username)
            end

            it "defines setters and getters only for the specified attribute" do
              expect(guest_order).to respond_to(:username)
              expect(guest_order).to respond_to(:username=)
              expect(guest_order).not_to respond_to(:password)
              expect(guest_order).not_to respond_to(:password=)
            end
          end

          describe :except do
            before do
              GuestOrder.reset_associate!(:user)
              GuestOrder.associate(:user, except: :username)
            end

            it "defines setters and getters for all attributes except for the specified attribute" do
              expect(guest_order).not_to respond_to(:username)
              expect(guest_order).not_to respond_to(:username=)
              expect(guest_order).to respond_to(:password)
              expect(guest_order).to respond_to(:password=)
            end
          end

          describe :class_name do

            describe "when specified" do
              before do
                AdminUser = Class.new(User)

                GuestOrder.reset_associate!(:user)
                GuestOrder.associate(:user, class_name: AdminUser)
              end

              it "uses the given class" do
                expect(guest_order.user).to be_an_instance_of(AdminUser)
              end
            end

            describe "when unspecified" do

              it "infers the class from the associate name" do
                expect(guest_order.user).to be_an_instance_of(User)
              end
            end
          end

        end

        describe "undefined model name", :skip do
          # @TODO Think wether it is a feature or not
          # Could be metadefined later
          it { expect { GuestOrder.send(:associate, :undefined) }.not_to raise_error }
        end

{'fraction_non_alphanumeric': 0.06821428571428571, 'fraction_numerical': 0.0, 'mean_word_length': 1.9391395592864638, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3184282', 'n_tokens_mistral': 761, 'n_tokens_neox': 714, 'n_words': 210}