Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added calculator new specs; fixed controller; #958

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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