Sha256: 86ab199f35554cae0d4128c54d3be314008e90f3a5c0dd4a3276e3732a5b94ba

Contents?: true

Size: 1.08 KB

Versions: 7

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

module RailsBestPractices::Core
  describe ModelAssociations do
    let(:model_associations) { described_class.new }

    before do
      model_associations.add_association('Project', 'project_manager', 'belongs_to')
      model_associations.add_association('Project', 'people', 'has_many', 'Person')
    end

    it 'gets model associations' do
      expect(model_associations.get_association('Project', 'project_manager')).to eq(
        'meta' => 'belongs_to', 'class_name' => 'ProjectManager'
      )
      expect(model_associations.get_association('Project', 'people')).to eq(
        'meta' => 'has_many', 'class_name' => 'Person'
      )
      expect(model_associations.get_association('Project', 'unknown')).to be_nil
    end

    it 'checks is model associatiosn' do
      expect(model_associations.is_association?('Project', 'project_manager')).to eq true
      expect(model_associations.is_association?('Project', 'people')).to eq true
      expect(model_associations.is_association?('Project', 'unknown')).to eq false
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rails_best_practices-1.23.2 spec/rails_best_practices/core/model_associations_spec.rb
rails_best_practices-1.23.1 spec/rails_best_practices/core/model_associations_spec.rb
rails_best_practices-1.23.0 spec/rails_best_practices/core/model_associations_spec.rb
rails_best_practices-1.22.1 spec/rails_best_practices/core/model_associations_spec.rb
rails_best_practices-1.22.0 spec/rails_best_practices/core/model_associations_spec.rb
rails_best_practices-1.21.0 spec/rails_best_practices/core/model_associations_spec.rb
rails_best_practices-1.20.1 spec/rails_best_practices/core/model_associations_spec.rb