Sha256: 29b72e0212403794c57a3f036925ad3991bfaceb937850378b6c13047c4e0eb9

Contents?: true

Size: 981 Bytes

Versions: 15

Compression:

Stored size: 981 Bytes

Contents

require "spec_helper"

describe BazaModels::Model::HasOneRelations do
  include DatabaseHelper

  let!(:user) { User.create!(email: "test@example.com", organization: organization) }
  let(:user_passport) { UserPassport.create(user: user) }
  let(:person) { Person.create!(user: user) }
  let(:role_user) { Role.create!(user: user, role: "user") }
  let!(:organization) { Organization.create!(name: "Test") }

  it "has one thorugh" do
    person
    expect(user.organization).to eq organization
    expect(user.person).to eq person
    expect(role_user.organization).to eq organization
  end

  context "destroy" do
    before do
      user.save!
    end

    it "restricts through has_one" do
      person
      expect { user.destroy! }.to raise_error(BazaModels::Errors::InvalidRecord)
    end

    it "destroys through has_one" do
      user_passport
      user.destroy!
      expect { user_passport.reload }.to raise_error(BazaModels::Errors::RecordNotFound)
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
baza_models-0.0.15 spec/baza_models/model/has_one_relations_spec.rb
baza_models-0.0.14 spec/baza_models/model/has_one_relations_spec.rb
baza_models-0.0.13 spec/baza_models/model/has_one_relations_spec.rb
baza_models-0.0.12 spec/baza_models/model/has_one_relations_spec.rb
baza_models-0.0.11 spec/baza_models/model/has_one_relations_spec.rb
baza_models-0.0.10 spec/baza_models/model/has_one_relations_spec.rb
baza_models-0.0.9 spec/baza_models/model/has_one_relations_spec.rb
baza_models-0.0.8 spec/baza_models/model/has_one_relations_spec.rb
baza_models-0.0.7 spec/baza_models/model/has_one_relations_spec.rb
baza_models-0.0.6 spec/baza_models/model/has_one_relations_spec.rb
baza_models-0.0.5 spec/baza_models/model/has_one_relations_spec.rb
baza_models-0.0.4 spec/baza_models/model/has_one_relations_spec.rb
baza_models-0.0.3 spec/baza_models/model/has_one_relations_spec.rb
baza_models-0.0.2 spec/baza_models/model/has_one_relations_spec.rb
baza_models-0.0.1 spec/baza_models/model/has_one_relations_spec.rb