diff options
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/factories/chouette_purchase_windows.rb | 16 | ||||
| -rw-r--r-- | spec/models/business_calendar_spec.rb | 5 | ||||
| -rw-r--r-- | spec/models/chouette/purchase_window_spec.rb | 27 | ||||
| -rw-r--r-- | spec/policies/purchase_window_policy_spec.rb | 15 | ||||
| -rw-r--r-- | spec/support/permissions.rb | 1 | 
5 files changed, 59 insertions, 5 deletions
| diff --git a/spec/factories/chouette_purchase_windows.rb b/spec/factories/chouette_purchase_windows.rb new file mode 100644 index 000000000..4d29a8801 --- /dev/null +++ b/spec/factories/chouette_purchase_windows.rb @@ -0,0 +1,16 @@ +FactoryGirl.define do +  factory :purchase_window, class: Chouette::PurchaseWindow do +    sequence(:name) { |n| "Purchase Window #{n}" } +    sequence(:objectid) { |n| "organisation:PurchaseWindow:#{n}:LOC" } +    date_ranges { [generate(:periods)] } + +    association :referential +     +  end + +  sequence :periods do |n| +    date = Date.today + 2*n +    date..(date+1) +  end +end + diff --git a/spec/models/business_calendar_spec.rb b/spec/models/business_calendar_spec.rb deleted file mode 100644 index 29f67d49f..000000000 --- a/spec/models/business_calendar_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -RSpec.describe BusinessCalendar, type: :model do -  pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/chouette/purchase_window_spec.rb b/spec/models/chouette/purchase_window_spec.rb new file mode 100644 index 000000000..702a44eeb --- /dev/null +++ b/spec/models/chouette/purchase_window_spec.rb @@ -0,0 +1,27 @@ +RSpec.describe Chouette::PurchaseWindow, :type => :model do +  let(:referential) {create(:referential)} +  subject  { create(:purchase_window, referential: referential) } + +  it { should belong_to(:referential) } +  it { is_expected.to validate_presence_of(:name) } + +  describe 'validations' do +    it 'validates and date_ranges do not overlap' do +      expect(build(:purchase_window, referential: referential,date_ranges: [Date.today..Date.today + 10.day, Date.yesterday..Date.tomorrow])).to_not be_valid +      # expect(build(periods: [Date.today..Date.today + 10.day, Date.yesterday..Date.tomorrow ])).to_not be_valid +    end +  end + +  describe 'before_validation' do +    let(:purchase_window) { build(:purchase_window, referential: referential, date_ranges: []) } + +    it 'shoud fill date_ranges with date ranges' do +      expected_range = Date.today..Date.tomorrow +      purchase_window.date_ranges << expected_range +      purchase_window.valid? + +      expect(purchase_window.date_ranges.map { |period| period.begin..period.end }).to eq([expected_range]) +    end +  end + +end diff --git a/spec/policies/purchase_window_policy_spec.rb b/spec/policies/purchase_window_policy_spec.rb new file mode 100644 index 000000000..f078bf288 --- /dev/null +++ b/spec/policies/purchase_window_policy_spec.rb @@ -0,0 +1,15 @@ +RSpec.describe PurchaseWindowPolicy, type: :policy do + +  let( :record ){ build_stubbed :purchase_window } +  before { stub_policy_scope(record) } + +  permissions :create? do +    it_behaves_like 'permitted policy and same organisation', "purchase_windows.create", archived: true +  end +  permissions :destroy? do +    it_behaves_like 'permitted policy and same organisation', "purchase_windows.destroy", archived: true +  end +  permissions :update? do +    it_behaves_like 'permitted policy and same organisation', "purchase_windows.update", archived: true +  end +end diff --git a/spec/support/permissions.rb b/spec/support/permissions.rb index dde530871..fc378babc 100644 --- a/spec/support/permissions.rb +++ b/spec/support/permissions.rb @@ -29,6 +29,7 @@ module Support          compliance_control_sets          compliance_control_blocks          compliance_check_sets +        purchase_windows        ]      end    end | 
