Skip to content

Commit

Permalink
Merge pull request #958 from ita-social-projects/new_calc_specs
Browse files Browse the repository at this point in the history
added calculator new specs; fixed controller;
  • Loading branch information
ktpe authored Nov 27, 2024
2 parents ae1497f + 0d8eb31 commit 62610c8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion spec/factories/calculators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
FactoryBot.define do
factory :calculator do
en_name { "English Calculator" }
uk_name { "Український калькуялтор" }
uk_name { "Український калькулятор" }
end
end
51 changes: 51 additions & 0 deletions spec/requests/account/calculators_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

let!(:calculator) { create(:calculator) }

let(:user) { create(:user) }
let(:locale) { "en" }
let(:new_path) { new_account_calculator_path(locale: locale) }

describe "DELETE #destroy" do
it "destroys the calculator and redirects" do
expect do
Expand Down Expand Up @@ -40,4 +44,51 @@
end
end
end

describe "GET #new" do
subject { get new_path }

context "when the user is authorized" do
it "initializes a new Calculator object with fields and formulas" do
subject

expect(response).to have_http_status(:ok)

calculator = assigns(:calculator)
expect(calculator).to be_a_new(Calculator)

expect(calculator.fields.size).to eq(1)
expect(calculator.formulas.size).to eq(1)

expect(calculator.fields.first).to be_a_new(Field)
expect(calculator.formulas.first).to be_a_new(Formula)
end

it "renders the new template" do
subject
expect(response).to render_template(:new)
end
end

context "when the locale is different" do
let(:locale) { "uk" }

it "handles the locale correctly" do
subject
expect(I18n.locale).to eq(:uk)
expect(response).to have_http_status(:ok)
end
end

context "when the user is not logged in" do
before do
sign_out(:user)
end

it "redirects to the login page" do
subject
expect(response).to redirect_to(new_user_session_path)
end
end
end
end

0 comments on commit 62610c8

Please sign in to comment.