generated from ita-social-projects/DevTemplate
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Increase coverage of project #934
Open
olexandervanzuriak
wants to merge
27
commits into
develop
Choose a base branch
from
930-increase-coverage-of-project
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
a5e39fa
Added user inactive_message method test
olexandervanzuriak f56c5da
Added test for calculator, message and product controllers
olexandervanzuriak 54f70de
Added tests for calculators preferable service
SleekMutt 32ec193
fixed formating
olexandervanzuriak 061a35d
Merge branch '930-increase-coverage-of-project' of github.com:ita-soc…
olexandervanzuriak a5f508b
fixed formatting
olexandervanzuriak d146105
Remove Channels group and added Services group to simplecov
olexandervanzuriak 9c816d6
Change the destroy products_controller method and added tests
olexandervanzuriak 18a457a
added home test
olexandervanzuriak a30cb4f
added post #calculate test
olexandervanzuriak d3f8f11
Added tests for models and helper
KseniaGovorun 5fdaec5
Fixed rubocop
KseniaGovorun cf45a54
Fixed in file application_helper
KseniaGovorun e634770
Added aplication controller tests
olexandervanzuriak 69bf828
Merge branch '930-increase-coverage-of-project' of github.com:ita-soc…
olexandervanzuriak 6cbcd50
Added tests for authorization
KseniaGovorun 08039a3
Fixed rubocop
KseniaGovorun 09668f9
Changed schema
KseniaGovorun 299d661
Fixed rubocop
KseniaGovorun 07ce648
Changed user model
KseniaGovorun aa10cfc
Added test blank_prices in product_spec
KseniaGovorun 509a6e0
Added migrate for authorization model
KseniaGovorun 0e7a248
Refactored tests
SleekMutt 5d71e05
Merge branch 'develop' of github.com:ita-social-projects/ZeroWaste in…
olexandervanzuriak 98c3767
Update gemlock
olexandervanzuriak 1296e1c
rubocop
olexandervanzuriak 92c0044
Fix request tests
olexandervanzuriak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
db/migrate/20241114131028_add_index_to_authorizations_on_uid_and_provider.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddIndexToAuthorizationsOnUidAndProvider < ActiveRecord::Migration[7.1] | ||
def change | ||
add_index :authorizations, [:uid, :provider], unique: true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FactoryBot.define do | ||
factory :authorization do | ||
uid { "unique_uid" } | ||
provider { "provider_name" } | ||
admin factory: [:user] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe ApplicationHelper, type: :helper do | ||
describe "#current_locale?" do | ||
context "when the current locale matches the given locale" do | ||
it "returns true" do | ||
I18n.with_locale(:en) do | ||
expect(helper.current_locale?(:en)).to be true | ||
end | ||
end | ||
end | ||
|
||
context "when the current locale does not match the given locale" do | ||
it "returns false" do | ||
I18n.with_locale(:en) do | ||
expect(helper.current_locale?(:uk)).to be false | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Authorization, type: :model do | ||
describe "associations" do | ||
it { is_expected.to belong_to(:admin).class_name("User").with_foreign_key("uid").optional.inverse_of(:authorizations) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,26 @@ | |
end | ||
end | ||
|
||
describe "#price_by_category" do | ||
let(:product) { create(:product, title: "Valid Title") } | ||
let(:category) { create(:category, :medium) } | ||
let(:valid_sum) { 10.0 } | ||
|
||
context "when the product has a price for the category" do | ||
let!(:existing_price) { create(:price, priceable: product, category: category, sum: valid_sum) } | ||
|
||
it "returns the price for the specified category" do | ||
expect(product.price_by_category(category)).to eq(existing_price) | ||
end | ||
end | ||
|
||
context "when the product does not have a price for the category" do | ||
it "returns nil" do | ||
expect(product.price_by_category(category)).to be_nil | ||
end | ||
end | ||
end | ||
|
||
describe "#find_or_build_price_for_category" do | ||
let(:product) { create(:product, title: "Valid Title") } | ||
let(:category) { create(:category, :medium) } | ||
|
@@ -91,4 +111,43 @@ | |
end | ||
end | ||
end | ||
|
||
describe ".diaper" do | ||
let!(:diaper_product) { create(:product, title: "diaper") } | ||
let!(:other_product) { create(:product, title: "shampoo") } | ||
|
||
it "returns the product with title 'diaper'" do | ||
expect(Product.diaper).to eq(diaper_product) | ||
end | ||
|
||
it "does not return a product with a different title" do | ||
expect(Product.diaper).not_to eq(other_product) | ||
end | ||
end | ||
|
||
describe "#blank_prices" do | ||
let(:product) { create(:product, title: "title") } | ||
|
||
context "when price sum is blank" do | ||
it "rejects nested attributes for price" do | ||
product.attributes = { | ||
prices_attributes: [ | ||
{ sum: nil } | ||
] | ||
} | ||
expect(product.prices).to be_empty | ||
end | ||
end | ||
|
||
context "when price sum is present" do | ||
it "accepts nested attributes for price" do | ||
product.attributes = { | ||
prices_attributes: [ | ||
{ sum: 100 } | ||
] | ||
} | ||
Comment on lines
+144
to
+148
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NEVER use local vars in specs |
||
expect(product.prices.size).to eq(1) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe ApplicationController, type: :controller do | ||
describe "GET #set_i18n_locale_from_params" do | ||
context "when an invalid locale is provided" do | ||
it "sets a flash notice about the unavailable translation" do | ||
get :redirection, params: { locale: "invalid_locale" } | ||
|
||
expect(flash.now[:notice]).to eq("invalid_locale translation not available") | ||
end | ||
end | ||
|
||
context "when a valid locale is provided" do | ||
it "does not set a flash notice" do | ||
get :redirection, params: { locale: "en" } | ||
|
||
expect(flash.now[:notice]).to be_nil | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SecureHex.uid якось так