Skip to content

Commit

Permalink
add test for sort in request tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriyAndriyovuch committed Sep 24, 2023
1 parent 67b19b5 commit 027eb1e
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ group :test do
gem "selenium-webdriver"
gem "simplecov", require: false
gem "shoulda-matchers", "~> 4.0"
gem "webdrivers"
gem "webdrivers", "~> 5.3.1"
gem "fuubar"
end

Expand Down
48 changes: 24 additions & 24 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ GEM
zeitwerk (~> 2.3)
acts_as_singleton (0.0.8)
activerecord (>= 3.1.0)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
airbrussh (1.4.1)
sshkit (>= 1.6.1, != 1.7.0)
annotate (3.2.0)
Expand Down Expand Up @@ -115,7 +115,7 @@ GEM
sshkit (~> 1.3)
capistrano-yarn (2.0.2)
capistrano (~> 3.0)
capybara (3.36.0)
capybara (3.39.2)
addressable
matrix
mini_mime (>= 0.1.3)
Expand All @@ -126,7 +126,6 @@ GEM
xpath (~> 3.2)
case_transform (0.2)
activesupport
childprocess (4.1.0)
cocoon (1.2.15)
codecov (0.6.0)
simplecov (>= 0.15, < 0.22)
Expand Down Expand Up @@ -259,8 +258,8 @@ GEM
mime-types-data (~> 3.2015)
mime-types-data (3.2021.1115)
mini_magick (4.11.0)
mini_mime (1.1.2)
mini_portile2 (2.6.1)
mini_mime (1.1.5)
mini_portile2 (2.8.4)
minitest (5.15.0)
msgpack (1.4.2)
multi_json (1.15.0)
Expand All @@ -270,14 +269,14 @@ GEM
net-ssh (>= 2.6.5, < 8.0.0)
net-ssh (7.0.1)
nio4r (2.5.8)
nokogiri (1.12.5)
mini_portile2 (~> 2.6.1)
nokogiri (1.15.4)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.12.5-arm64-darwin)
nokogiri (1.15.4-arm64-darwin)
racc (~> 1.4)
nokogiri (1.12.5-x64-mingw32)
nokogiri (1.15.4-x64-mingw32)
racc (~> 1.4)
nokogiri (1.12.5-x86_64-linux)
nokogiri (1.15.4-x86_64-linux)
racc (~> 1.4)
oauth2 (1.4.7)
faraday (>= 0.8, < 2.0)
Expand Down Expand Up @@ -324,15 +323,15 @@ GEM
method_source (~> 1.0)
pry-rails (0.3.9)
pry (>= 0.10.4)
public_suffix (4.0.6)
public_suffix (5.0.3)
puma (5.5.2)
nio4r (~> 2.0)
racc (1.6.0)
rack (2.2.3)
racc (1.7.1)
rack (2.2.8)
rack-mini-profiler (2.3.3)
rack (>= 1.2.0)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rack-test (2.1.0)
rack (>= 1.3)
rails (6.1.4.4)
actioncable (= 6.1.4.4)
actionmailbox (= 6.1.4.4)
Expand Down Expand Up @@ -372,15 +371,15 @@ GEM
rb-inotify (0.10.1)
ffi (~> 1.0)
redis (4.5.1)
regexp_parser (2.2.0)
regexp_parser (2.8.1)
request_store (1.5.1)
rack (>= 1.4)
requestjs-rails (0.0.10)
rails (>= 6.0.0)
responders (3.0.1)
actionpack (>= 5.0)
railties (>= 5.0)
rexml (3.2.5)
rexml (3.2.6)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
Expand Down Expand Up @@ -440,10 +439,10 @@ GEM
sawyer (0.8.2)
addressable (>= 2.3.5)
faraday (> 0.8, < 2.0)
selenium-webdriver (4.1.0)
childprocess (>= 0.5, < 5.0)
selenium-webdriver (4.10.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
shoulda-matchers (4.5.1)
activesupport (>= 4.2.0)
sidekiq (6.3.1)
Expand Down Expand Up @@ -517,10 +516,11 @@ GEM
activemodel (>= 6.0.0)
bindex (>= 0.4.0)
railties (>= 6.0.0)
webdrivers (5.0.0)
webdrivers (5.3.1)
nokogiri (~> 1.6)
rubyzip (>= 1.3.0)
selenium-webdriver (~> 4.0)
selenium-webdriver (~> 4.0, < 4.11)
websocket (1.2.10)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand Down Expand Up @@ -609,7 +609,7 @@ DEPENDENCIES
toastr-rails
tzinfo-data
web-console (>= 4.1.0)
webdrivers
webdrivers (~> 5.3.1)

RUBY VERSION
ruby 3.0.6p216
Expand Down
6 changes: 6 additions & 0 deletions spec/features/account/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
expect(page.find("#users > :first-child > :first-child")).to have_content User.last.email
expect(page.find("#users > :last-child > :first-child")).to have_content User.first.email
end

it "by non existing parameter" do
visit account_users_path(sort: "nonexistingparameter asc")

expect(page).to have_content I18n.t("sort.sort_error")
end
end

context "when user clicks show icon" do
Expand Down
23 changes: 23 additions & 0 deletions spec/requests/account/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,29 @@
end
end

describe "GET :index with sorting" do
it "by id asc" do
get account_users_path(sort: "id asc")

expect(response).to be_successful
expect(assigns(:users).first).to eq(User.first)
end

it "by id desc" do
get account_users_path(sort: "id desc")

expect(response).to be_successful
expect(assigns(:users).first).to eq(User.last)
end

it "by non existing parameter" do
get account_users_path(sort: "nonexistingparameter asc")

expect(response).not_to be_successful
expect(flash[:alert]).to eq(I18n.t("sort.sort_error"))
end
end

describe "GET #new" do
it "returns a successful response" do
get new_account_user_path
Expand Down
25 changes: 25 additions & 0 deletions spec/requests/calculators_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,31 @@
end
end

describe "GET /calculator with sorting" do
include_context :authorize_admin

it "by id asc" do
get account_calculators_path(sort: "id asc")

expect(response).to be_successful
expect(assigns(:calculators).first).to eq(Calculator.first)
end

it "by id desc" do
get account_calculators_path(sort: "id desc")

expect(response).to be_successful
expect(assigns(:calculators).first).to eq(Calculator.last)
end

it "by non existing parameter" do
get account_calculators_path(sort: "nonexistingparameter asc")

expect(response).not_to be_successful
expect(flash[:alert]).to eq(I18n.t("sort.sort_error"))
end
end

describe "POST #create" do
include_context :authorize_admin

Expand Down
24 changes: 24 additions & 0 deletions spec/requests/categories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

RSpec.describe Account::CategoriesController, type: :request do
let!(:category) { create(:category, :budgetary) }
let!(:category) { create(:category, :medium) }
let(:valid_attributes) { { category: { name: "medium" }} }
let(:invalid_attributes) { { category: { name: "" }} }
let(:new_attributes) { { category: { name: "premium" }} }
Expand All @@ -16,6 +17,29 @@
end
end

describe "GET :index with sorting" do
it "by id asc" do
get account_categories_path(sort: "id asc")

expect(response).to be_successful
expect(assigns(:categories).first).to eq(Category.first)
end

it "by id desc" do
get account_categories_path(sort: "id desc")

expect(response).to be_successful
expect(assigns(:categories).first).to eq(Category.last)
end

it "by non existing parameter" do
get account_categories_path(sort: "nonexistingparameter asc")

expect(response).not_to be_successful
expect(flash[:alert]).to eq(I18n.t("sort.sort_error"))
end
end

describe "GET :new" do
it "is successful" do
get new_account_category_path
Expand Down
23 changes: 23 additions & 0 deletions spec/requests/products_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,29 @@
end
end

describe "GET :index with sorting" do
it "by id asc" do
get account_products_path(sort: "id asc")

expect(response).to be_successful
expect(assigns(:products).first).to eq(Product.first)
end

it "by id desc" do
get account_products_path(sort: "id desc")

expect(response).to be_successful
expect(assigns(:products).first).to eq(Product.last)
end

it "by non existing parameter" do
get account_products_path(sort: "nonexistingparameter asc")

expect(response).not_to be_successful
expect(flash[:alert]).to eq(I18n.t("sort.sort_error"))
end
end

describe "GET :new" do
it "is successful" do
get new_account_product_path
Expand Down

0 comments on commit 027eb1e

Please sign in to comment.