Skip to content

Instantly share code, notes, and snippets.

@kamilhism
Last active August 29, 2015 14:06
Show Gist options
  • Save kamilhism/5bc809dbe3f91070b0a3 to your computer and use it in GitHub Desktop.
Save kamilhism/5bc809dbe3f91070b0a3 to your computer and use it in GitHub Desktop.
schema
require 'rails_helper'
describe Job do
let(:job) { create(:job) }
let(:mailshop) { create(:mailshop, name: 'Sisk Mailshop') }
let(:version_params) do
{
name: 'U2',
mailshop: mailshop,
quantity: 100_500,
mail_date: DateTime.new(2000, 10, 10),
seeds_sent: 100,
seeds_scanned: 500
}
end
describe 'callbacks' do
let(:version) { build(:version, version_params) }
describe 'after adding version' do
it "updates job's overall statistic" do
expected_statistic = {
'seeds_sent' => 100,
'seeds_scanned' => 500,
'total_quantity' => 100,
'mailshop' => 'Sisk Mailshop',
'mail_date' => '2000-10-10T00:00:00.000Z'
}
job.update_attribute(:versions, [version])
expect(job.overall_statistic).to match(expected_statistic)
end
end
end
describe '#grouped_scfs' do
let!(:version) { create(:version, version_params.merge(job: job)) }
let!(:seed) { create(:seed, job: job, version: version) }
it 'returns grouped scfs with seeds data' do
expected_scfs = [{
scf: seed.scf,
seeds_data: { seeds_scanned: 1 }
}]
expect(job.grouped_scfs).to match(expected_scfs)
end
end
end
  create_table "states" do |t|
    t.string "name"
  end
  create_table "scfs", do |t|
    t.string  "name"
    t.string  "zip"
    t.integer "state_id"
  end

1

  create_table "versions", do |t|
    t.string  "name"
    t.integer "quantity"
    t.integer "seeds_sent"
    t.integer "seeds_scaned"
    t.integer "job_id"
    t.column  "seeds", :json
  end
seeds = {
  seed_1: {
    identificator: '00321312312343',
    scf_id: 4,
    zip: '5507'
  },
  seed_2: {
    identificator: '00232635646245',
    scf_id: 22,
    zip: '6019'
  },
  .
  .
  .
}
seeds = {
  scf_4: [
    {
      id: 1,
      identificator: '00321312312343',
      zip: '5507'
    },
    .
    .
    .
  ],
  scf_22: [
    {
      id: 2,
      identificator: '00232635646245',
      zip: '6019'
    },
    .
    .
    .
  ]
}

2

  create_table "versions", do |t|
    t.string  "name"
    t.integer "quantity"
    t.integer "seeds_sent"
    t.integer "seeds_scaned"
    t.integer "job_id"
  end
  create_table "seeds", do |t|
    t.string  "identificator"
    t.string  "zip"
    t.integer "version_id"
    t.integer "scf_id"
  end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment