Sha256: 71ab9ffbe14d1222b11b48e0a142dee5ad66f30c3eacb97b09fb3cbdb64251a7

Contents?: true

Size: 1.36 KB

Versions: 31

Compression:

Stored size: 1.36 KB

Contents

require "rails_helper"

describe Dorsale::Alexandrie::AttachmentsController, type: :controller do
  routes { Dorsale::Engine.routes }

  let(:uploaded_file){
    path = Rails.root.join("../../spec/files/pdf.pdf").to_s
    Rack::Test::UploadedFile.new(path, "application/pdf")
  }

  let(:valid_attributes){
    attachable = DummyModel.create!(name: "A")

    {
      :attachable_id   => attachable.id,
      :attachable_type => attachable.class.to_s,
      :file            => uploaded_file,
    }
  }

  let(:user) {
    create(:user)
  }

  before :each do
    sign_in user
  end

  describe "create" do
    it "should create attachment" do
      post :create, attachment: valid_attributes, back_url: "/"
      expect(assigns(:attachment)).to be_persisted
    end

    it "should redirect to back_url" do
      post :create, attachment: valid_attributes, back_url: "/"
      expect(response).to redirect_to("/")
    end
  end

  describe "destroy" do
    it "should delete attachment" do
      attachment = create(:alexandrie_attachment)
      expect {
        delete :destroy, id: attachment, back_url: "/"
      }.to change(::Dorsale::Alexandrie::Attachment, :count).by(-1)
    end

    it "should redirect to back_url" do
      attachment = create(:alexandrie_attachment)
      delete :destroy, id: attachment, back_url: "/"
      expect(response).to redirect_to("/")
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
dorsale-2.6.1 spec/controllers/dorsale/alexandrie/attachments_controller_spec.rb
dorsale-2.6.0 spec/controllers/dorsale/alexandrie/attachments_controller_spec.rb
dorsale-2.5.0 spec/controllers/dorsale/alexandrie/attachments_controller_spec.rb
dorsale-2.4.3 spec/controllers/dorsale/alexandrie/attachments_controller_spec.rb
dorsale-2.4.2 spec/controllers/dorsale/alexandrie/attachments_controller_spec.rb
dorsale-2.4.1 spec/controllers/dorsale/alexandrie/attachments_controller_spec.rb
dorsale-2.4.0 spec/controllers/dorsale/alexandrie/attachments_controller_spec.rb
dorsale-2.3.5 spec/controllers/dorsale/alexandrie/attachments_controller_spec.rb
dorsale-2.3.4 spec/controllers/dorsale/alexandrie/attachments_controller_spec.rb
dorsale-2.3.3 spec/controllers/dorsale/alexandrie/attachments_controller_spec.rb
dorsale-2.3.2 spec/controllers/dorsale/alexandrie/attachments_controller_spec.rb
dorsale-2.3.1 spec/controllers/dorsale/alexandrie/attachments_controller_spec.rb
dorsale-2.3.0 spec/controllers/dorsale/alexandrie/attachments_controller_spec.rb
dorsale-2.2.16 spec/controllers/dorsale/alexandrie/attachments_controller_spec.rb
dorsale-2.2.15 spec/controllers/dorsale/alexandrie/attachments_controller_spec.rb
dorsale-2.2.14 spec/controllers/dorsale/alexandrie/attachments_controller_spec.rb
dorsale-2.2.13 spec/controllers/dorsale/alexandrie/attachments_controller_spec.rb
dorsale-2.2.12 spec/controllers/dorsale/alexandrie/attachments_controller_spec.rb
dorsale-2.2.11 spec/controllers/dorsale/alexandrie/attachments_controller_spec.rb
dorsale-2.2.10 spec/controllers/dorsale/alexandrie/attachments_controller_spec.rb