diff options
| -rw-r--r-- | app/models/workbench.rb | 7 | ||||
| -rw-r--r-- | app/models/workgroup.rb | 1 | ||||
| -rw-r--r-- | spec/features/workbenches/workbenches_show_spec.rb | 42 | 
3 files changed, 49 insertions, 1 deletions
| diff --git a/app/models/workbench.rb b/app/models/workbench.rb index f49f4e7cf..b80fa64ac 100644 --- a/app/models/workbench.rb +++ b/app/models/workbench.rb @@ -31,7 +31,12 @@ class Workbench < ActiveRecord::Base      if line_ids.empty?        Referential.none      else -      Referential.joins(:metadatas).where(['referential_metadata.line_ids && ARRAY[?]::bigint[]', line_ids]).ready.not_in_referential_suite +      workgroup +        .referentials +        .joins(:metadatas) +        .where(['referential_metadata.line_ids && ARRAY[?]::bigint[]', line_ids]) +        .ready +        .not_in_referential_suite      end    end diff --git a/app/models/workgroup.rb b/app/models/workgroup.rb index 511bbfeb0..3d761e81f 100644 --- a/app/models/workgroup.rb +++ b/app/models/workgroup.rb @@ -4,6 +4,7 @@ class Workgroup < ActiveRecord::Base    has_many :workbenches    has_many :organisations, through: :workbenches +  has_many :referentials, through: :workbenches    validates_uniqueness_of :name diff --git a/spec/features/workbenches/workbenches_show_spec.rb b/spec/features/workbenches/workbenches_show_spec.rb index 2b215bb03..7be813b94 100644 --- a/spec/features/workbenches/workbenches_show_spec.rb +++ b/spec/features/workbenches/workbenches_show_spec.rb @@ -22,6 +22,48 @@ RSpec.describe 'Workbenches', type: :feature do        end      end +    it 'lists referentials in the current workgroup' do +      other_workbench = create( +        :workbench, +        line_referential: line_ref, +        workgroup: workbench.workgroup +      ) +      other_referential = create( +        :workbench_referential, +        workbench: other_workbench, +        organisation: other_workbench.organisation, +        metadatas: [ +          create( +            :referential_metadata, +            lines: [create(:line, line_referential: line_ref)] +          ) +        ] +      ) + +      hidden_referential = create( +        :workbench_referential, +        workbench: create( +          :workbench, +          line_referential: line_ref +        ), +        metadatas: [ +          create( +            :referential_metadata, +            lines: [create(:line, line_referential: line_ref)] +          ) +        ] +      ) + +      visit workbench_path(workbench) + +      expect(page).to have_content(referential.name), +        "Couldn't find `referential`: `#{referential.inspect}`" +      expect(page).to have_content(other_referential.name), +        "Couldn't find `other_referential`: `#{other_referential.inspect}`" +      expect(page).to_not have_content(hidden_referential.name), +        "Couldn't find `hidden_referential`: `#{hidden_referential.inspect}`" +    end +      context 'filtering' do        let!(:another_organisation) { create :organisation }        let(:another_line) { create :line, line_referential: line_ref } | 
