diff --git a/app/models/spree/ability_decorator.rb b/app/models/spree/ability_decorator.rb index b10c781fac..13efc7e109 100644 --- a/app/models/spree/ability_decorator.rb +++ b/app/models/spree/ability_decorator.rb @@ -57,6 +57,7 @@ class AbilityDecorator def add_group_management_abilities(user) can [:admin, :index], :overview + can [:admin, :sync], :analytic can [:admin, :index], EnterpriseGroup can [:read, :edit, :update], EnterpriseGroup do |group| user.owned_groups.include? group @@ -69,6 +70,7 @@ class AbilityDecorator can [:create, :search], nil can [:admin, :index], :overview + can [:admin, :sync], :analytic can [:admin, :index, :read, :create, :edit, :update_positions, :destroy], ProducerProperty diff --git a/spec/features/admin/overview_spec.rb b/spec/features/admin/overview_spec.rb index ebe6a1d379..30f2cc0336 100644 --- a/spec/features/admin/overview_spec.rb +++ b/spec/features/admin/overview_spec.rb @@ -110,5 +110,45 @@ feature %q{ end end end + + context "with the spree dash configured" do + let(:d1) { create(:distributor_enterprise) } + + before do + stub_jirafe + @enterprise_user.enterprise_roles.build(enterprise: d1).save + end + + around do |example| + with_dash_configured { example.run } + end + + it "has permission to sync analytics" do + visit '/admin' + expect(page).to have_content d1.name + end + end end -end \ No newline at end of file + + private + + def stub_jirafe + stub_request(:post, "https://api.jirafe.com/v1/applications/abc123/resources?token="). + to_return(:status => 200, :body => "", :headers => {}) + end + + def with_dash_configured(&block) + Spree::Dash::Config.preferred_app_id = 'abc123' + Spree::Dash::Config.preferred_site_id = 'abc123' + Spree::Dash::Config.preferred_token = 'abc123' + expect(Spree::Dash::Config.configured?).to be true + + block.call + + ensure + Spree::Dash::Config.preferred_app_id = nil + Spree::Dash::Config.preferred_site_id = nil + Spree::Dash::Config.preferred_token = nil + expect(Spree::Dash::Config.configured?).to be false + end +end