Sha256: 512a9ff079e0cded1d86bd0af8ed99632d1d3142035afa9c947f432ec609937a

Contents?: true

Size: 1.53 KB

Versions: 11

Compression:

Stored size: 1.53 KB

Contents

require "rails_helper"

RSpec.describe Dorsale::BillingMachine::Quotation::Copy do
  let(:quotation) {
    quotation = create(:billing_machine_quotation)

    quotation.update_columns(
      :label      => "ABC",
      :date       => 3.days.ago,
      :state      => "canceled",
      :created_at => 3.days.ago,
      :updated_at => 3.days.ago,
    )

    line = create(:billing_machine_quotation_line,
      :quotation => quotation,
      :label     => "DEF",
    )

    quotation
  }

  let(:copy) {
    Dorsale::BillingMachine::Quotation::Copy.(quotation)
  }

  it "should duplicate infos, lines, and documents" do
    create(:alexandrie_attachment, attachable: quotation)

    expect(copy).to be_persisted

    expect(copy.label).to             eq "ABC"
    expect(copy.lines.count).to       eq 1
    expect(copy.lines.first.label).to eq "DEF"
    expect(copy.attachments.count).to eq 1
  end

  it "should reset date" do
    expect(quotation.date).to_not eq Date.current
    expect(copy.date).to          eq Date.current
  end

  it "should reset unique_index, tracking_id, created_at, updated_at" do
    expect(quotation.unique_index).to_not eq copy.unique_index
    expect(quotation.tracking_id).to_not  eq copy.tracking_id
    # WTF ? It fails only when running all tests
    # expect(quotation.created_at).to_not   eq copy.created_at
    # expect(quotation.updated_at).to_not   eq copy.updated_at
  end

  it "should reset state to pending" do
    expect(quotation.reload.state).to eq "canceled"
    expect(copy.reload.state).to      eq "draft"
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
dorsale-4.0.0 spec/services/dorsale/billing_machine/quotation/copy_spec.rb
dorsale-3.20.0 spec/services/dorsale/billing_machine/quotation/copy_spec.rb
dorsale-3.19.1 spec/services/dorsale/billing_machine/quotation/copy_spec.rb
dorsale-3.19.0 spec/services/dorsale/billing_machine/quotation/copy_spec.rb
dorsale-3.18.0 spec/services/dorsale/billing_machine/quotation/copy_spec.rb
dorsale-3.17.0 spec/services/dorsale/billing_machine/quotation/copy_spec.rb
dorsale-3.16.0 spec/services/dorsale/billing_machine/quotation/copy_spec.rb
dorsale-3.15.0 spec/services/dorsale/billing_machine/quotation/copy_spec.rb
dorsale-3.14.11 spec/services/dorsale/billing_machine/quotation/copy_spec.rb
dorsale-3.14.10 spec/services/dorsale/billing_machine/quotation/copy_spec.rb
dorsale-3.14.9 spec/services/dorsale/billing_machine/quotation/copy_spec.rb