Skip to content

Commit

Permalink
Добавлены тесты
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon committed Jul 27, 2020
1 parent f9099f1 commit 9344c14
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 12 deletions.
2 changes: 1 addition & 1 deletion apps/web/views/interviews/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def company_information(company)
# last_rating_time = RelativeTime.in_words(company.created_at, locale: :ru)
company_link = link_to company.name, company.url

raw "Компания #{company_link}, рейтинг #{company.rating_total.rou}"
raw "Компания #{company_link}, рейтинг #{company.rating_total.round}"
end
end
end
Expand Down
16 changes: 15 additions & 1 deletion spec/interviews/operations/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
end

let(:interview_repo) { instance_double('InterviewRepository', create_with_interview_rating: Interview.new) }
let(:company_repo) { instance_double('CompanyRepository') }
let(:company_repo) { instance_double('CompanyRepository', update_interview_statistic: Company.new) }

let(:params) do
{
Expand All @@ -29,6 +29,20 @@
context 'when successful operation' do
it { expect(subject).to be_success }
it { expect(subject.value!).to be_a(Interview) }

it 'calls company statistic updater' do
expect(company_repo).to receive(:update_interview_statistic).with(
10,
{
author_id: 0,

overall_impression: 3.0,
recommendation: 3.0
}
)

subject
end
end

context 'when interview data is invalid' do
Expand Down
6 changes: 3 additions & 3 deletions spec/web/controllers/interviews/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
let(:operation) { ->(*) { Success(Vacancy.new(id: 123)) } }
let(:success_flash) { 'Отзыв успешно создан.' }

it { expect(subject).to redirect_to '/companies/1' }
it { expect(subject).to redirect_to '/companies/1/interviews' }

it 'shows flash message' do
subject
Expand All @@ -44,7 +44,7 @@
let(:operation) { ->(*) { Failure(:error) } }
let(:flash_message) { 'Произошла ошибка, пожалуйста повторите позже' }

it { expect(subject).to redirect_to '/companies/1' }
it { expect(subject).to redirect_to '/companies/1/interviews' }

it 'shows flash message' do
subject
Expand All @@ -59,7 +59,7 @@
let(:company_id) { Fabricate(:company).id }
let(:action) { described_class.new }

it { expect(subject).to redirect_to "/companies/#{company_id}" }
it { expect(subject).to redirect_to "/companies/#{company_id}/interviews" }
end

context 'when not authorised' do
Expand Down
53 changes: 47 additions & 6 deletions spec/web/controllers/interviews/index_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,50 @@
RSpec.describe Web::Controllers::Interviews::::Index, type: :action do
let(:action) { described_class.new }
let(:params) { Hash[] }
RSpec.describe Web::Controllers::Interviews::Index, type: :action do
subject { action.call(params) }

it 'is successful' do
response = action.call(params)
expect(response[0]).to eq 200
let(:action) { described_class.new(operation: operation, interview_operation: interview_operation) }

let(:params) { { id: 0 } }

context 'when operation returns success value' do
let(:operation) { ->(*) { Success(Company.new(id: 0)) } }
let(:interview_operation) { ->(*) { Success([Interview.new]) } }

it { expect(subject).to be_success }

it 'call operation with a right contract' do
expect(operation).to receive(:call).with(id: 0)
subject
end

it 'exposes vacancy' do
subject
expect(action.company).to eq(Company.new(id: 0))
expect(action.interviews).to eq([Interview.new])
end
end

context 'when operation returns failure value' do
let(:operation) { ->(*) { Failure(:not_found) } }
let(:interview_operation) { ->(*) { Success([Interview.new]) } }

it { expect(subject).to redirect_to '/companies' }

it 'call operation with a right contract' do
expect(operation).to receive(:call).with(id: 0)
subject
end
end

context 'with real dependencies' do
subject { action.call(params) }

let(:action) { described_class.new }
let(:params) { { id: company.id } }

let(:company) { Fabricate.create(:company) }

before { Fabricate(:review, company_id: company.id) }

it { expect(subject).to be_success }
end
end
2 changes: 1 addition & 1 deletion spec/web/views/interviews/index_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RSpec.describe Web::Views::Interviews::::Index, type: :view do
RSpec.describe Web::Views::Interviews::Index, type: :view do
let(:exposures) { Hash[format: :html] }
let(:template) { Hanami::View::Template.new('apps/web/templates/interviews/index.html.slim') }
let(:view) { described_class.new(template, exposures) }
Expand Down

0 comments on commit 9344c14

Please sign in to comment.