-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1858 from trade-tariff/GL-359-add-pseudo-measures…
…-models GL-359 Add pseudo measures models
- Loading branch information
Showing
11 changed files
with
224 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module GreenLanes | ||
class Exemption < Sequel::Model(:green_lanes_exemptions) | ||
plugin :timestamps, update_on_create: true | ||
plugin :auto_validations, not_null: :presence | ||
plugin :association_pks | ||
|
||
many_to_many :category_assessments, | ||
join_table: :green_lanes_category_assessments_exemptions | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module GreenLanes | ||
class Measure < Sequel::Model(:green_lanes_measures) | ||
plugin :timestamps, update_on_create: true | ||
plugin :auto_validations, not_null: :presence | ||
|
||
many_to_one :category_assessment | ||
many_to_one :goods_nomenclature, class: 'GoodsNomenclature', | ||
primary_key: %i[goods_nomenclature_item_id producline_suffix], | ||
key: %i[goods_nomenclature_item_id productline_suffix] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FactoryBot.define do | ||
factory :green_lanes_exemption, class: 'GreenLanes::Exemption' do | ||
transient do | ||
category_assessments { [] } | ||
end | ||
|
||
sequence(:code) { |n| sprintf '%04d', n } | ||
description { Forgery(:basic).text } | ||
category_assessment_pks { category_assessments.map(&:pk) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FactoryBot.define do | ||
factory :green_lanes_measure, class: 'GreenLanes::Measure' do | ||
transient do | ||
category_assessment { create :category_assessment } | ||
goods_nomenclature { create :commodity } | ||
end | ||
|
||
category_assessment_id { category_assessment.id } | ||
goods_nomenclature_item_id { goods_nomenclature.goods_nomenclature_item_id } | ||
productline_suffix { goods_nomenclature.producline_suffix } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
RSpec.describe GreenLanes::Exemption do | ||
describe 'attributes' do | ||
it { is_expected.to respond_to :id } | ||
it { is_expected.to respond_to :code } | ||
it { is_expected.to respond_to :description } | ||
it { is_expected.to respond_to :created_at } | ||
it { is_expected.to respond_to :updated_at } | ||
end | ||
|
||
describe 'validations' do | ||
subject(:errors) { instance.tap(&:valid?).errors } | ||
|
||
let(:instance) { described_class.new } | ||
|
||
it { is_expected.to include code: ['is not present'] } | ||
it { is_expected.to include description: ['is not present'] } | ||
|
||
context 'with duplicate code' do | ||
let(:existing) { create :green_lanes_exemption } | ||
let(:instance) { build :green_lanes_exemption, code: existing.code } | ||
|
||
it { is_expected.to include code: ['is already taken'] } | ||
end | ||
end | ||
|
||
describe '#associations' do | ||
describe '#category_assessments' do | ||
subject { exemption.reload.category_assessments } | ||
|
||
let :exemption do | ||
create(:green_lanes_exemption).tap do |exempt| | ||
exempt.add_category_assessment create(:category_assessment) | ||
end | ||
end | ||
|
||
it { is_expected.to include instance_of GreenLanes::CategoryAssessment } | ||
end | ||
|
||
describe '#category_assessments_pks' do | ||
subject { exemption.reload.category_assessment_pks } | ||
|
||
let :exemption do | ||
create(:green_lanes_exemption).tap do |exempt| | ||
exempt.category_assessment_pks = assessments.map(&:pk) | ||
exempt.save | ||
end | ||
end | ||
|
||
let(:assessments) { create_list :category_assessment, 1 } | ||
|
||
it { is_expected.to match_array assessments.map(&:id) } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
RSpec.describe GreenLanes::Measure do | ||
describe 'attributes' do | ||
it { is_expected.to respond_to :id } | ||
it { is_expected.to respond_to :category_assessment_id } | ||
it { is_expected.to respond_to :goods_nomenclature_item_id } | ||
it { is_expected.to respond_to :productline_suffix } | ||
it { is_expected.to respond_to :created_at } | ||
it { is_expected.to respond_to :updated_at } | ||
end | ||
|
||
describe 'validations' do | ||
subject(:errors) { instance.tap(&:valid?).errors } | ||
|
||
let(:instance) { described_class.new } | ||
|
||
it { is_expected.to include category_assessment_id: ['is not present'] } | ||
it { is_expected.to include goods_nomenclature_item_id: ['is not present'] } | ||
it { is_expected.to include productline_suffix: ['is not present'] } | ||
|
||
context 'with duplicate associations' do | ||
let(:existing) { create :green_lanes_measure } | ||
|
||
let :instance do | ||
build :green_lanes_measure, | ||
category_assessment_id: existing.category_assessment_id, | ||
goods_nomenclature_item_id: existing.goods_nomenclature_item_id, | ||
productline_suffix: existing.productline_suffix | ||
end | ||
|
||
let :uniqueness_key do | ||
%i[category_assessment_id goods_nomenclature_item_id productline_suffix] | ||
end | ||
|
||
it { is_expected.to include uniqueness_key => ['is already taken'] } | ||
end | ||
end | ||
|
||
describe 'associations' do | ||
describe '#category_assessment' do | ||
subject { measure.category_assessment } | ||
|
||
let(:measure) { create :green_lanes_measure, category_assessment_id: ca.id } | ||
let(:ca) { create :category_assessment } | ||
|
||
it { is_expected.to be_instance_of GreenLanes::CategoryAssessment } | ||
end | ||
|
||
describe '#goods_nomenclature' do | ||
subject { measure.goods_nomenclature } | ||
|
||
let :measure do | ||
create :green_lanes_measure, | ||
goods_nomenclature_item_id: gn.goods_nomenclature_item_id, | ||
productline_suffix: gn.producline_suffix | ||
end | ||
|
||
let(:gn) { create :commodity } | ||
|
||
it { is_expected.to be_instance_of Commodity } | ||
end | ||
end | ||
end |