<commit_before>require File.join(File.dirname(__FILE__), '../test_helper.rb')

module ModelStubs
  class ModelStub < ActiveRecord::Base
    abstract_class = true
    def self.columns; [ActiveRecord::ConnectionAdapters::Column.new('foo', '')] end
    def self.table_name
      to_s.split('::').last.underscore.pluralize
    end
  end

  ##
  ## Standard associations
  ##

  class Address < ModelStub
    belongs_to :addressable, :polymorphic => true
  end

  class User < ModelStub
    has_and_belongs_to_many :roles
    has_one :subscription
    has_one :address, :as => :addressable
  end

  class Service < ModelStub
    has_many :subscriptions
    has_many :users, :through => :subscriptions
  end

  class Subscription < ModelStub
    belongs_to :service
    belongs_to :user
  end

  class Role < ModelStub
    has_and_belongs_to_many :users
  end

  ##
  ## These versions of the associations require extra configuration to work properly
  ##

  class OtherAddress < ModelStub
    set_table_name 'addresses'
    belongs_to :other_addressable, :polymorphic => true
  end

  class OtherUser < ModelStub
    set_table_name 'users'
    has_and_belongs_to_many :other_roles, :class_name => 'ModelStubs::OtherRole', :foreign_key => 'user_id', :association_foreign_key => 'role_id', :join_table => 'roles_users'
    has_one :other_subscription, :class_name => 'ModelStubs::OtherSubscription', :foreign_key => 'user_id'
    has_one :other_address, :as => :other_addressable, :class_name => 'ModelStubs::OtherAddress', :foreign_key => 'addressable_id'
  end

  class OtherService < ModelStub
    set_table_name 'services'
    has_many :other_subscriptions, :class_name => 'ModelStubs::OtherSubscription', :foreign_key => 'service_id'
    has_many :other_users, :through => :subscriptions # :class_name and :foreign_key are ignored for :through
  end

  class OtherSubscription < ModelStub
    set_table_name 'subscriptions'
    belongs_to :other_service, :class_name => 'ModelStubs::OtherService', :foreign_key => 'service_id'
    belongs_to :other_user, :class_name => 'ModelStubs::OtherUser', :foreign_key => 'user_id'
  end

  class OtherRole < ModelStub
    set_table_name 'roles'
    has_and_belongs_to_many :other_users, :class_name => 'ModelStubs::OtherUser', :foreign_key => 'role_id', :association_foreign_key => 'user_id', :join_table => 'roles_users'
  end
end

class ConstraintsTestObject
  # stub out what the mixin expects to find ...
  def self.before_filter(*args); end
  attr_accessor :active_scaffold_joins
  attr_accessor :active_scaffold_habtm_joins
  attr_accessor :active_scaffold_config<commit_msg>Fix constraint tests<commit_after>require File.join(File.dirname(__FILE__), '../test_helper.rb')

module ModelStubs
  class ModelStub < ActiveRecord::Base
    abstract_class = true
    def self.columns; [ActiveRecord::ConnectionAdapters::Column.new('foo', '')] end
    def self.table_name
      to_s.split('::').last.underscore.pluralize
    end
    self.store_full_sti_class = false
  end

  ##
  ## Standard associations
  ##

  class Address < ModelStub
    belongs_to :addressable, :polymorphic => true
  end

  class User < ModelStub
    has_and_belongs_to_many :roles
    has_one :subscription
    has_one :address, :as => :addressable
  end

  class Service < ModelStub
    has_many :subscriptions
    has_many :users, :through => :subscriptions
  end

  class Subscription < ModelStub
    belongs_to :service
    belongs_to :user
  end

  class Role < ModelStub
    has_and_belongs_to_many :users
  end

  ##
  ## These versions of the associations require extra configuration to work properly
  ##

  class OtherAddress < ModelStub
    set_table_name 'addresses'
    belongs_to :other_addressable, :polymorphic => true
  end

  class OtherUser < ModelStub
    set_table_name 'users'
    has_and_belongs_to_many :other_roles, :class_name => 'ModelStubs::OtherRole', :foreign_key => 'user_id', :association_foreign_key => 'role_id', :join_table => 'roles_users'
    has_one :other_subscription, :class_name => 'ModelStubs::OtherSubscription', :foreign_key => 'user_id'
    has_one :other_address, :as => :other_addressable, :class_name => 'ModelStubs::OtherAddress', :foreign_key => 'addressable_id'
  end

  class OtherService < ModelStub
    set_table_name 'services'
    has_many :other_subscriptions, :class_name => 'ModelStubs::OtherSubscription', :foreign_key => 'service_id'
    has_many :other_users, :through => :other_subscriptions # :class_name and :foreign_key are ignored for :through
  end

  class OtherSubscription < ModelStub
    set_table_name 'subscriptions'
    belongs_to :other_service, :class_name => 'ModelStubs::OtherService', :foreign_key => 'service_id'
    belongs_to :other_user, :class_name => 'ModelStubs::OtherUser', :foreign_key => 'user_id'
  end

  class OtherRole < ModelStub
    set_table_name 'roles'
    has_and_belongs_to_many :other_users, :class_name => 'ModelStubs::OtherUser', :foreign_key => 'role_id', :association_foreign_key => 'user_id', :join_table => 'roles_users'
  end
end

class ConstraintsTestObject
  # stub out what the mixin expects to find ...
  def self.before_filter(*args); end
  attr_accessor :active_scaffold_joins
  attr_accessor :active_scaffold_habtm_joins
  attr_accessor :active_scaffold_config
{'fraction_non_alphanumeric': 0.09982983550765741, 'fraction_numerical': 0.0, 'mean_word_length': 4.81958195819582, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 51, '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': '6587405', 'n_tokens_mistral': 1733, 'n_tokens_neox': 1723, 'n_words': 389}