Sha256: 2fe888c38df53b3182591ef96255dc8dddbaf89b1964cf4a37c0e8a35886d21e

Contents?: true

Size: 1.34 KB

Versions: 13

Compression:

Stored size: 1.34 KB

Contents

require 'spec_helper'

module Spree
  describe Api::ClassificationsController, type: :controller do
    let(:taxon) do
      taxon = create(:taxon)

      3.times do
        product = create(:product)
        product.taxons << taxon
      end
      taxon
    end

    before do
      stub_authentication!
    end

    context "as a user" do
      it "cannot change the order of a product" do
        api_put :update, taxon_id: taxon, product_id: taxon.products.first, position: 1
        expect(response.status).to eq(401)
      end
    end

    context "as an admin" do
      sign_in_as_admin!

      let(:last_product) { taxon.products.last }

      it "can change the order a product" do
        classification = taxon.classifications.find_by(product_id: last_product.id)
        expect(classification.position).to eq(3)
        api_put :update, taxon_id: taxon, product_id: last_product, position: 0
        expect(response.status).to eq(200)
        expect(classification.reload.position).to eq(1)
      end

      it "should touch the taxon" do
        taxon.update_attributes(updated_at: Time.current - 10.seconds)
        taxon_last_updated_at = taxon.updated_at
        api_put :update, taxon_id: taxon, product_id: last_product, position: 0
        taxon.reload
        expect(taxon_last_updated_at.to_i).to_not eq(taxon.updated_at.to_i)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
solidus_api-1.3.2 spec/controllers/spree/api/classifications_controller_spec.rb
solidus_api-1.2.3 spec/controllers/spree/api/classifications_controller_spec.rb
solidus_api-1.3.1 spec/controllers/spree/api/classifications_controller_spec.rb
solidus_api-1.3.0 spec/controllers/spree/api/classifications_controller_spec.rb
solidus_api-1.3.0.rc2 spec/controllers/spree/api/classifications_controller_spec.rb
solidus_api-1.3.0.rc1 spec/controllers/spree/api/classifications_controller_spec.rb
solidus_api-1.3.0.beta1 spec/controllers/spree/api/classifications_controller_spec.rb
solidus_api-1.2.2 spec/controllers/spree/api/classifications_controller_spec.rb
solidus_api-1.2.1 spec/controllers/spree/api/classifications_controller_spec.rb
solidus_api-1.2.0 spec/controllers/spree/api/classifications_controller_spec.rb
solidus_api-1.2.0.rc2 spec/controllers/spree/api/classifications_controller_spec.rb
solidus_api-1.2.0.rc1 spec/controllers/spree/api/classifications_controller_spec.rb
solidus_api-1.2.0.beta1 spec/controllers/spree/api/classifications_controller_spec.rb