From 8b0492496dbd29e39345fe8c04668c65a0f9fe56 Mon Sep 17 00:00:00 2001 From: topnimble <90754900+topnimble@users.noreply.github.com> Date: Tue, 23 May 2023 17:17:11 +0700 Subject: [PATCH 01/27] Adjust styles --- app/views/home/index.html.erb | 6 ----- app/views/layouts/application.html.erb | 32 ++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 4402bd8..8e780d3 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -1,9 +1,3 @@ -<% if user_signed_in? %> -
Welcome <%= current_user.email %>
- <%= button_to "Sign out", destroy_user_session_path, method: :delete %> -<% else %> - <%= button_to "Sign in", new_user_session_path %> -<% end %>

Welcome to the world of scrapping!!

\ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index bcf85f8..6134124 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -8,11 +8,35 @@ <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> <%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %> - + -

<%= notice %>

-

<%= alert %>

- <%= yield %> +
+
+
+ <%= link_to "Google Scrapper", root_url, class: "navbar-brand col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0" %> + + <% if user_signed_in? %> +
Welcome <%= current_user.email %>
+ <%= button_to "Sign out", destroy_user_session_path, method: :delete, class: "btn btn-outline-light" %> + <% else %> + <%= button_to "Sign in", new_user_session_path, class: "btn btn-outline-light" %> + <% end %> +
+
+
+ +
+
+ <% if notice %> +

<%= notice %>

+ <% end %> + <% if alert %> +

<%= alert %>

+ <% end %> + + <%= yield %> +
+
From 1fde2ae25a033585db11189c22ea605a958fc7e4 Mon Sep 17 00:00:00 2001 From: topnimble <90754900+topnimble@users.noreply.github.com> Date: Tue, 23 May 2023 17:31:45 +0700 Subject: [PATCH 02/27] Update link --- app/views/layouts/application.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 6134124..83d4fa2 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -20,7 +20,7 @@
Welcome <%= current_user.email %>
<%= button_to "Sign out", destroy_user_session_path, method: :delete, class: "btn btn-outline-light" %> <% else %> - <%= button_to "Sign in", new_user_session_path, class: "btn btn-outline-light" %> + <%= button_to "Sign in", new_user_session_path, method: :get, class: "btn btn-outline-light" %> <% end %> From d238321792eb5d27cada936653f8547fcf75d5d5 Mon Sep 17 00:00:00 2001 From: topnimble <90754900+topnimble@users.noreply.github.com> Date: Tue, 23 May 2023 18:01:38 +0700 Subject: [PATCH 03/27] Adjust styles --- app/views/layouts/application.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 83d4fa2..63c3f46 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -17,7 +17,7 @@ <%= link_to "Google Scrapper", root_url, class: "navbar-brand col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0" %> <% if user_signed_in? %> -
Welcome <%= current_user.email %>
+
Welcome <%= current_user.email %>
<%= button_to "Sign out", destroy_user_session_path, method: :delete, class: "btn btn-outline-light" %> <% else %> <%= button_to "Sign in", new_user_session_path, method: :get, class: "btn btn-outline-light" %> @@ -27,7 +27,7 @@
-
+
<% if notice %>

<%= notice %>

<% end %> From e9475215ce73b072bd1cf2b87e0c1fbdb1c5ca84 Mon Sep 17 00:00:00 2001 From: topnimble <90754900+topnimble@users.noreply.github.com> Date: Thu, 25 May 2023 11:10:10 +0700 Subject: [PATCH 04/27] Add tests --- .../authentications/sign_in/sign_in_spec.rb | 57 +++++++++++++++++++ .../authentications/sign_out/sign_out_spec.rb | 20 +++++++ 2 files changed, 77 insertions(+) create mode 100644 spec/systems/authentications/sign_in/sign_in_spec.rb create mode 100644 spec/systems/authentications/sign_out/sign_out_spec.rb diff --git a/spec/systems/authentications/sign_in/sign_in_spec.rb b/spec/systems/authentications/sign_in/sign_in_spec.rb new file mode 100644 index 0000000..b1e7391 --- /dev/null +++ b/spec/systems/authentications/sign_in/sign_in_spec.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'Sign in page', type: :system do + let(:selectors) do + { + auth_form: '.new_user', + email_field: 'user[email]', + password_field: 'user[password]' + } + end + + context 'given the Sign in button is clicked' do + context 'given the credentials are valid' do + it 'displays the home page' do + visit new_user_session_path + user = Fabricate(:user) + submit_authentication_form(user.email, user.password) + + expect(page).to have_current_path(root_path) + end + end + + context 'given the credentials are invalid' do + it 'displays the Sign in page' do + visit new_user_session_path + user = Fabricate(:user, password: 'password') + + submit_authentication_form(user.email, 'invalidemail') + + expect(page).to have_current_path(new_user_session_path) + end + + it 'shows the error message' do + visit new_user_session_path + user = Fabricate(:user, password: 'password') + + submit_authentication_form(user.email, 'invalidemail') + + within selectors[:auth_form] do + expect(page).to have_text "Your email address or password is incorrect." + end + end + end + end + + private + + def submit_authentication_form(email, password) + within selectors[:auth_form] do + fill_in selectors[:email_field], with: email + fill_in selectors[:password_field], with: password + click_button "Sign In" + end + end +end diff --git a/spec/systems/authentications/sign_out/sign_out_spec.rb b/spec/systems/authentications/sign_out/sign_out_spec.rb new file mode 100644 index 0000000..b862f29 --- /dev/null +++ b/spec/systems/authentications/sign_out/sign_out_spec.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'Sign out', type: :system do + let(:selectors) do + { + sign_out_button: '.sign-out-button' + } + end + + it 'redirects to the login page' do + # log in + visit root_path + + click_link selectors[:sign_out_button] + + expect(page).to have_current_path(new_user_session_path) + end +end From 4eca8d1f38766b8680080c4015d529d8fec5e143 Mon Sep 17 00:00:00 2001 From: topnimble <90754900+topnimble@users.noreply.github.com> Date: Fri, 26 May 2023 10:06:34 +0700 Subject: [PATCH 05/27] Update helper --- spec/rails_helper.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 4522b79..1132a10 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -21,4 +21,9 @@ config.infer_spec_type_from_file_location! config.include Rails.application.routes.url_helpers + + config.include Devise::Test::ControllerHelpers, type: :view + config.include Devise::Test::ControllerHelpers, type: :controller + config.include Devise::Test::IntegrationHelpers, type: :feature + config.include Devise::Test::IntegrationHelpers, type: :request end From da5e74cb828d31299b09c38d821ca2b27a61f29c Mon Sep 17 00:00:00 2001 From: topnimble <90754900+topnimble@users.noreply.github.com> Date: Fri, 26 May 2023 10:06:49 +0700 Subject: [PATCH 06/27] Change CI to true --- .env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.env b/.env index b236d56..a0b3aae 100644 --- a/.env +++ b/.env @@ -2,5 +2,5 @@ DOCKER_REGISTRY_HOST=docker.io DOCKER_IMAGE=mosharaf13/google_scrapper_ruby BRANCH_TAG=latest PORT=80 -CI=false +CI=true TEST_RETRY=0 From d2df8a0c0ee28d10462ddbfdeed65bdcf3edcc04 Mon Sep 17 00:00:00 2001 From: topnimble <90754900+topnimble@users.noreply.github.com> Date: Fri, 26 May 2023 10:06:58 +0700 Subject: [PATCH 07/27] Add classes --- app/views/layouts/application.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 63c3f46..5d0281f 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -18,9 +18,9 @@ <% if user_signed_in? %>
Welcome <%= current_user.email %>
- <%= button_to "Sign out", destroy_user_session_path, method: :delete, class: "btn btn-outline-light" %> + <%= button_to "Sign out", destroy_user_session_path, method: :delete, class: "btn btn-outline-light sign-out-button" %> <% else %> - <%= button_to "Sign in", new_user_session_path, method: :get, class: "btn btn-outline-light" %> + <%= button_to "Sign in", new_user_session_path, method: :get, class: "btn btn-outline-light sign-in-button" %> <% end %>
From 1abbda9075518c42eff2dd66ee0ef3d1e9cd9199 Mon Sep 17 00:00:00 2001 From: topnimble <90754900+topnimble@users.noreply.github.com> Date: Fri, 26 May 2023 10:14:26 +0700 Subject: [PATCH 08/27] Update helper --- spec/rails_helper.rb | 5 ----- spec/support/devise.rb | 9 +++++++++ 2 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 spec/support/devise.rb diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 1132a10..4522b79 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -21,9 +21,4 @@ config.infer_spec_type_from_file_location! config.include Rails.application.routes.url_helpers - - config.include Devise::Test::ControllerHelpers, type: :view - config.include Devise::Test::ControllerHelpers, type: :controller - config.include Devise::Test::IntegrationHelpers, type: :feature - config.include Devise::Test::IntegrationHelpers, type: :request end diff --git a/spec/support/devise.rb b/spec/support/devise.rb new file mode 100644 index 0000000..490428f --- /dev/null +++ b/spec/support/devise.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +RSpec.configure do |config| + config.include Devise::Test::ControllerHelpers, type: :controller + config.include Devise::Test::ControllerHelpers, type: :view + config.include Devise::Test::ControllerHelpers, type: :helper + config.include Devise::Test::IntegrationHelpers, type: :feature + config.include Devise::Test::IntegrationHelpers, type: :request +end From 193159fd4879f007fb5d4204cf17111b9ee887b5 Mon Sep 17 00:00:00 2001 From: topnimble <90754900+topnimble@users.noreply.github.com> Date: Fri, 26 May 2023 10:19:34 +0700 Subject: [PATCH 09/27] Update tests --- spec/fabricators/user_fabricator.rb | 6 ++++++ spec/support/user_authentication.rb | 5 +++++ spec/systems/authentications/sign_out/sign_out_spec.rb | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 spec/fabricators/user_fabricator.rb create mode 100644 spec/support/user_authentication.rb diff --git a/spec/fabricators/user_fabricator.rb b/spec/fabricators/user_fabricator.rb new file mode 100644 index 0000000..8dc4dbe --- /dev/null +++ b/spec/fabricators/user_fabricator.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +Fabricator(:user) do + email { FFaker::Internet.email } + password { FFaker::Internet.password } +end diff --git a/spec/support/user_authentication.rb b/spec/support/user_authentication.rb new file mode 100644 index 0000000..393ea06 --- /dev/null +++ b/spec/support/user_authentication.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +def login_as_user(user = Fabricate(:user)) + sign_in user +end diff --git a/spec/systems/authentications/sign_out/sign_out_spec.rb b/spec/systems/authentications/sign_out/sign_out_spec.rb index b862f29..7492fe0 100644 --- a/spec/systems/authentications/sign_out/sign_out_spec.rb +++ b/spec/systems/authentications/sign_out/sign_out_spec.rb @@ -10,7 +10,7 @@ end it 'redirects to the login page' do - # log in + login_as_user visit root_path click_link selectors[:sign_out_button] From b2074516f5b173c1833adbea566a198bf01dcde4 Mon Sep 17 00:00:00 2001 From: topnimble <90754900+topnimble@users.noreply.github.com> Date: Fri, 26 May 2023 10:23:11 +0700 Subject: [PATCH 10/27] Update tests --- spec/systems/authentications/sign_in/sign_in_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/systems/authentications/sign_in/sign_in_spec.rb b/spec/systems/authentications/sign_in/sign_in_spec.rb index b1e7391..bb8c451 100644 --- a/spec/systems/authentications/sign_in/sign_in_spec.rb +++ b/spec/systems/authentications/sign_in/sign_in_spec.rb @@ -27,7 +27,7 @@ visit new_user_session_path user = Fabricate(:user, password: 'password') - submit_authentication_form(user.email, 'invalidemail') + submit_authentication_form(user.email, 'invalid') expect(page).to have_current_path(new_user_session_path) end @@ -36,7 +36,7 @@ visit new_user_session_path user = Fabricate(:user, password: 'password') - submit_authentication_form(user.email, 'invalidemail') + submit_authentication_form(user.email, 'invalid') within selectors[:auth_form] do expect(page).to have_text "Your email address or password is incorrect." From 739839f76c60b2b52ee8dc46fd9b192b52fccd81 Mon Sep 17 00:00:00 2001 From: topnimble <90754900+topnimble@users.noreply.github.com> Date: Fri, 26 May 2023 15:42:58 +0700 Subject: [PATCH 11/27] Remove tests --- .../authentications/sign_in/sign_in_spec.rb | 57 ------------------- .../authentications/sign_out/sign_out_spec.rb | 20 ------- 2 files changed, 77 deletions(-) delete mode 100644 spec/systems/authentications/sign_in/sign_in_spec.rb delete mode 100644 spec/systems/authentications/sign_out/sign_out_spec.rb diff --git a/spec/systems/authentications/sign_in/sign_in_spec.rb b/spec/systems/authentications/sign_in/sign_in_spec.rb deleted file mode 100644 index bb8c451..0000000 --- a/spec/systems/authentications/sign_in/sign_in_spec.rb +++ /dev/null @@ -1,57 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -describe 'Sign in page', type: :system do - let(:selectors) do - { - auth_form: '.new_user', - email_field: 'user[email]', - password_field: 'user[password]' - } - end - - context 'given the Sign in button is clicked' do - context 'given the credentials are valid' do - it 'displays the home page' do - visit new_user_session_path - user = Fabricate(:user) - submit_authentication_form(user.email, user.password) - - expect(page).to have_current_path(root_path) - end - end - - context 'given the credentials are invalid' do - it 'displays the Sign in page' do - visit new_user_session_path - user = Fabricate(:user, password: 'password') - - submit_authentication_form(user.email, 'invalid') - - expect(page).to have_current_path(new_user_session_path) - end - - it 'shows the error message' do - visit new_user_session_path - user = Fabricate(:user, password: 'password') - - submit_authentication_form(user.email, 'invalid') - - within selectors[:auth_form] do - expect(page).to have_text "Your email address or password is incorrect." - end - end - end - end - - private - - def submit_authentication_form(email, password) - within selectors[:auth_form] do - fill_in selectors[:email_field], with: email - fill_in selectors[:password_field], with: password - click_button "Sign In" - end - end -end diff --git a/spec/systems/authentications/sign_out/sign_out_spec.rb b/spec/systems/authentications/sign_out/sign_out_spec.rb deleted file mode 100644 index 7492fe0..0000000 --- a/spec/systems/authentications/sign_out/sign_out_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -describe 'Sign out', type: :system do - let(:selectors) do - { - sign_out_button: '.sign-out-button' - } - end - - it 'redirects to the login page' do - login_as_user - visit root_path - - click_link selectors[:sign_out_button] - - expect(page).to have_current_path(new_user_session_path) - end -end From f26988e15fa42b1e343f09fee1f92fc9f8bd4633 Mon Sep 17 00:00:00 2001 From: topnimble <90754900+topnimble@users.noreply.github.com> Date: Mon, 29 May 2023 10:03:14 +0700 Subject: [PATCH 12/27] Remove controller part --- spec/support/devise.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/support/devise.rb b/spec/support/devise.rb index 490428f..f2d43a6 100644 --- a/spec/support/devise.rb +++ b/spec/support/devise.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true RSpec.configure do |config| - config.include Devise::Test::ControllerHelpers, type: :controller config.include Devise::Test::ControllerHelpers, type: :view config.include Devise::Test::ControllerHelpers, type: :helper config.include Devise::Test::IntegrationHelpers, type: :feature From de01aa5d9bb0f7d281d189a4e098897ff6144a59 Mon Sep 17 00:00:00 2001 From: topnimble <90754900+topnimble@users.noreply.github.com> Date: Mon, 29 May 2023 10:04:43 +0700 Subject: [PATCH 13/27] Adjust function name Co-authored-by: Sang Huynh Thanh <63148598+sanG-github@users.noreply.github.com> --- spec/support/user_authentication.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/support/user_authentication.rb b/spec/support/user_authentication.rb index 393ea06..0749674 100644 --- a/spec/support/user_authentication.rb +++ b/spec/support/user_authentication.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -def login_as_user(user = Fabricate(:user)) +def login_as(user = Fabricate(:user)) sign_in user end From 38d71203d10ff4a6a95458e99c39144f722a64ce Mon Sep 17 00:00:00 2001 From: topnimble <90754900+topnimble@users.noreply.github.com> Date: Mon, 29 May 2023 10:10:07 +0700 Subject: [PATCH 14/27] Ignore `.env` --- .env | 6 ------ .gitignore | 2 ++ 2 files changed, 2 insertions(+), 6 deletions(-) delete mode 100644 .env diff --git a/.env b/.env deleted file mode 100644 index a0b3aae..0000000 --- a/.env +++ /dev/null @@ -1,6 +0,0 @@ -DOCKER_REGISTRY_HOST=docker.io -DOCKER_IMAGE=mosharaf13/google_scrapper_ruby -BRANCH_TAG=latest -PORT=80 -CI=true -TEST_RETRY=0 diff --git a/.gitignore b/.gitignore index 598c995..42dbee7 100644 --- a/.gitignore +++ b/.gitignore @@ -65,3 +65,5 @@ yarn-error.log* # Ignore Gemfile.lock file in engines. /engines/*/Gemfile.lock + +.env \ No newline at end of file From 89288007a5415464e5c2fcc9c9d67c616096e78d Mon Sep 17 00:00:00 2001 From: topnimble <90754900+topnimble@users.noreply.github.com> Date: Mon, 29 May 2023 10:15:31 +0700 Subject: [PATCH 15/27] Change double quotes to single quote --- app/views/layouts/application.html.erb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 5d0281f..194845b 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -6,21 +6,21 @@ <%= csrf_meta_tags %> <%= csp_meta_tag %> - <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> - <%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %> + <%= stylesheet_link_tag 'application', 'data-turbo-track': 'reload' %> + <%= javascript_include_tag 'application', 'data-turbo-track': 'reload', defer: true %>
- <%= link_to "Google Scrapper", root_url, class: "navbar-brand col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0" %> + <%= link_to 'Google Scrapper', root_url, class: 'navbar-brand col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0' %> <% if user_signed_in? %>
Welcome <%= current_user.email %>
- <%= button_to "Sign out", destroy_user_session_path, method: :delete, class: "btn btn-outline-light sign-out-button" %> + <%= button_to 'Sign out', destroy_user_session_path, method: :delete, class: 'btn btn-outline-light sign-out-button' %> <% else %> - <%= button_to "Sign in", new_user_session_path, method: :get, class: "btn btn-outline-light sign-in-button" %> + <%= button_to 'Sign in', new_user_session_path, method: :get, class: 'btn btn-outline-light sign-in-button' %> <% end %>
From 209c140fdfabb81463572a4c7fab2dc9e29e3ae0 Mon Sep 17 00:00:00 2001 From: topnimble <90754900+topnimble@users.noreply.github.com> Date: Mon, 29 May 2023 11:50:44 +0700 Subject: [PATCH 16/27] Extract header --- app/views/layouts/application.html.erb | 15 +-------------- app/views/shared/_header.erb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 14 deletions(-) create mode 100644 app/views/shared/_header.erb diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 194845b..4334de7 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -11,20 +11,7 @@ -
-
-
- <%= link_to 'Google Scrapper', root_url, class: 'navbar-brand col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0' %> - - <% if user_signed_in? %> -
Welcome <%= current_user.email %>
- <%= button_to 'Sign out', destroy_user_session_path, method: :delete, class: 'btn btn-outline-light sign-out-button' %> - <% else %> - <%= button_to 'Sign in', new_user_session_path, method: :get, class: 'btn btn-outline-light sign-in-button' %> - <% end %> -
-
-
+ <%= render 'shared/header' %>
diff --git a/app/views/shared/_header.erb b/app/views/shared/_header.erb new file mode 100644 index 0000000..8770bf1 --- /dev/null +++ b/app/views/shared/_header.erb @@ -0,0 +1,14 @@ +
+
+
+ <%= link_to 'Google Scrapper', root_url, class: 'navbar-brand col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0' %> + + <% if user_signed_in? %> +
Welcome <%= current_user.email %>
+ <%= button_to 'Sign out', destroy_user_session_path, method: :delete, class: 'btn btn-outline-light sign-out-button' %> + <% else %> + <%= button_to 'Sign in', new_user_session_path, method: :get, class: 'btn btn-outline-light sign-in-button' %> + <% end %> +
+
+
From 36570e8497bc5fbb66b5eeaf609e92aa468867e5 Mon Sep 17 00:00:00 2001 From: topnimble <90754900+topnimble@users.noreply.github.com> Date: Mon, 29 May 2023 11:58:45 +0700 Subject: [PATCH 17/27] Extract flashes --- app/views/layouts/application.html.erb | 7 +------ app/views/shared/_flashes.erb | 7 +++++++ 2 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 app/views/shared/_flashes.erb diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 4334de7..0da2e62 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -15,12 +15,7 @@
- <% if notice %> -

<%= notice %>

- <% end %> - <% if alert %> -

<%= alert %>

- <% end %> + <%= render 'shared/flashes' %> <%= yield %>
diff --git a/app/views/shared/_flashes.erb b/app/views/shared/_flashes.erb new file mode 100644 index 0000000..40e99f3 --- /dev/null +++ b/app/views/shared/_flashes.erb @@ -0,0 +1,7 @@ +<% if notice %> +

<%= notice %>

+<% end %> + +<% if alert %> +

<%= alert %>

+<% end %> From 9c7f0a2fa8e88a615a6e951a2aee886eeb7a7e21 Mon Sep 17 00:00:00 2001 From: topnimble <90754900+topnimble@users.noreply.github.com> Date: Mon, 29 May 2023 17:20:03 +0700 Subject: [PATCH 18/27] Add port 80 --- .github/workflows/test_production_build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test_production_build.yml b/.github/workflows/test_production_build.yml index 33bb029..325125f 100644 --- a/.github/workflows/test_production_build.yml +++ b/.github/workflows/test_production_build.yml @@ -10,6 +10,7 @@ on: env: DOCKER_REGISTRY_HOST: ${{ secrets.DOCKER_REGISTRY_HOST }} DOCKER_IMAGE: ${{ github.repository }} + PORT: 80 concurrency: group: ${{ github.workflow }}-${{ github.ref }} From f7746c4dca500e204bdda5ea8c0a14c6fdeaa779 Mon Sep 17 00:00:00 2001 From: topnimble <90754900+topnimble@users.noreply.github.com> Date: Tue, 30 May 2023 10:25:27 +0700 Subject: [PATCH 19/27] Add tests --- .../authentications/sign_in/sign_in_spec.rb | 57 +++++++++++++++++++ .../authentications/sign_out/sign_out_spec.rb | 20 +++++++ 2 files changed, 77 insertions(+) create mode 100644 spec/systems/authentications/sign_in/sign_in_spec.rb create mode 100644 spec/systems/authentications/sign_out/sign_out_spec.rb diff --git a/spec/systems/authentications/sign_in/sign_in_spec.rb b/spec/systems/authentications/sign_in/sign_in_spec.rb new file mode 100644 index 0000000..bb8c451 --- /dev/null +++ b/spec/systems/authentications/sign_in/sign_in_spec.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'Sign in page', type: :system do + let(:selectors) do + { + auth_form: '.new_user', + email_field: 'user[email]', + password_field: 'user[password]' + } + end + + context 'given the Sign in button is clicked' do + context 'given the credentials are valid' do + it 'displays the home page' do + visit new_user_session_path + user = Fabricate(:user) + submit_authentication_form(user.email, user.password) + + expect(page).to have_current_path(root_path) + end + end + + context 'given the credentials are invalid' do + it 'displays the Sign in page' do + visit new_user_session_path + user = Fabricate(:user, password: 'password') + + submit_authentication_form(user.email, 'invalid') + + expect(page).to have_current_path(new_user_session_path) + end + + it 'shows the error message' do + visit new_user_session_path + user = Fabricate(:user, password: 'password') + + submit_authentication_form(user.email, 'invalid') + + within selectors[:auth_form] do + expect(page).to have_text "Your email address or password is incorrect." + end + end + end + end + + private + + def submit_authentication_form(email, password) + within selectors[:auth_form] do + fill_in selectors[:email_field], with: email + fill_in selectors[:password_field], with: password + click_button "Sign In" + end + end +end diff --git a/spec/systems/authentications/sign_out/sign_out_spec.rb b/spec/systems/authentications/sign_out/sign_out_spec.rb new file mode 100644 index 0000000..863e351 --- /dev/null +++ b/spec/systems/authentications/sign_out/sign_out_spec.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'Sign out', type: :system do + let(:selectors) do + { + sign_out_button: '.sign-out-button' + } + end + + it 'redirects to the root page' do + login_as + visit root_path + + click_link selectors[:sign_out_button] + + expect(page).to have_current_path(root_path) + end +end From 10f901cd406b3c455fb62f2b0dde5f101436d51e Mon Sep 17 00:00:00 2001 From: topnimble <90754900+topnimble@users.noreply.github.com> Date: Tue, 30 May 2023 13:26:35 +0700 Subject: [PATCH 20/27] Include for system type --- spec/support/system.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/support/system.rb b/spec/support/system.rb index 5001ae7..d4144fe 100644 --- a/spec/support/system.rb +++ b/spec/support/system.rb @@ -2,6 +2,8 @@ RSpec.configure do |config| config.before(:each, type: :system) do + config.include Warden::Test::Helpers, type: :system + # use headless_chrome, by default driven_by :headless_chrome From 4742156df39de267b9981a6121ca5ff8a15cfbf6 Mon Sep 17 00:00:00 2001 From: topnimble <90754900+topnimble@users.noreply.github.com> Date: Tue, 30 May 2023 13:34:12 +0700 Subject: [PATCH 21/27] Rename function --- spec/support/user_authentication.rb | 2 +- spec/systems/authentications/sign_out/sign_out_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/support/user_authentication.rb b/spec/support/user_authentication.rb index 0749674..393ea06 100644 --- a/spec/support/user_authentication.rb +++ b/spec/support/user_authentication.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -def login_as(user = Fabricate(:user)) +def login_as_user(user = Fabricate(:user)) sign_in user end diff --git a/spec/systems/authentications/sign_out/sign_out_spec.rb b/spec/systems/authentications/sign_out/sign_out_spec.rb index 863e351..3802d6f 100644 --- a/spec/systems/authentications/sign_out/sign_out_spec.rb +++ b/spec/systems/authentications/sign_out/sign_out_spec.rb @@ -10,7 +10,7 @@ end it 'redirects to the root page' do - login_as + login_as_user visit root_path click_link selectors[:sign_out_button] From 0e53c6734df6937d9f8cf5095f2f0d4247e4a8b9 Mon Sep 17 00:00:00 2001 From: topnimble <90754900+topnimble@users.noreply.github.com> Date: Thu, 1 Jun 2023 11:33:00 +0700 Subject: [PATCH 22/27] Add custom log in page --- app/views/devise/sessions/new.erb | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 app/views/devise/sessions/new.erb diff --git a/app/views/devise/sessions/new.erb b/app/views/devise/sessions/new.erb new file mode 100644 index 0000000..ac9ee2a --- /dev/null +++ b/app/views/devise/sessions/new.erb @@ -0,0 +1,33 @@ +
+

Log in

+ +
+
+ <%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> +
+ <%= f.label :email %>
+ <%= f.email_field :email, autofocus: true, autocomplete: 'email', class: 'form-control' %> +
+ +
+ <%= f.label :password %>
+ <%= f.password_field :password, autocomplete: 'current-password', class: 'form-control' %> +
+ + <% if devise_mapping.rememberable? %> +
+ <%= f.check_box :remember_me, class: 'form-check-input' %> + <%= f.label :remember_me, class: 'form-check-label' %> +
+ <% end %> + +
+
+ <%= f.submit 'Log in', class: 'btn btn-primary m-1' %> +
+ <%= render 'devise/shared/links' %> +
+ <% end %> +
+
+
From 79af39ff8372d10e978703c7447408574c61b366 Mon Sep 17 00:00:00 2001 From: Sang Huynh Date: Tue, 30 May 2023 17:18:06 +0700 Subject: [PATCH 23/27] Fix sign_in method does not exist --- spec/support/user_authentication.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/support/user_authentication.rb b/spec/support/user_authentication.rb index 393ea06..9f7080d 100644 --- a/spec/support/user_authentication.rb +++ b/spec/support/user_authentication.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true def login_as_user(user = Fabricate(:user)) - sign_in user + login_as user end From d2abab78843c03ed613a86202324656c944a634d Mon Sep 17 00:00:00 2001 From: Sang Huynh Date: Tue, 30 May 2023 17:05:29 +0700 Subject: [PATCH 24/27] Fix sign in tests --- .../authentications/sign_in/sign_in_spec.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/spec/systems/authentications/sign_in/sign_in_spec.rb b/spec/systems/authentications/sign_in/sign_in_spec.rb index bb8c451..ba1d578 100644 --- a/spec/systems/authentications/sign_in/sign_in_spec.rb +++ b/spec/systems/authentications/sign_in/sign_in_spec.rb @@ -15,7 +15,7 @@ context 'given the credentials are valid' do it 'displays the home page' do visit new_user_session_path - user = Fabricate(:user) + user = Fabricate.build(:user) submit_authentication_form(user.email, user.password) expect(page).to have_current_path(root_path) @@ -25,22 +25,20 @@ context 'given the credentials are invalid' do it 'displays the Sign in page' do visit new_user_session_path - user = Fabricate(:user, password: 'password') + user = Fabricate.build(:user, password: 'password') submit_authentication_form(user.email, 'invalid') - expect(page).to have_current_path(new_user_session_path) + expect(page).to have_current_path(root_path) end it 'shows the error message' do visit new_user_session_path - user = Fabricate(:user, password: 'password') + user = Fabricate.build(:user, password: 'password') submit_authentication_form(user.email, 'invalid') - within selectors[:auth_form] do - expect(page).to have_text "Your email address or password is incorrect." - end + expect(page).to have_text "Invalid Email or password." end end end @@ -51,7 +49,7 @@ def submit_authentication_form(email, password) within selectors[:auth_form] do fill_in selectors[:email_field], with: email fill_in selectors[:password_field], with: password - click_button "Sign In" + click_button "Log in" end end end From 98e9bf026e2bbc85764531b2e932e508ba71bbd7 Mon Sep 17 00:00:00 2001 From: topnimble <90754900+topnimble@users.noreply.github.com> Date: Fri, 16 Jun 2023 15:01:49 +0700 Subject: [PATCH 25/27] Fix linting --- spec/systems/authentications/sign_in/sign_in_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/systems/authentications/sign_in/sign_in_spec.rb b/spec/systems/authentications/sign_in/sign_in_spec.rb index ba1d578..83a0a80 100644 --- a/spec/systems/authentications/sign_in/sign_in_spec.rb +++ b/spec/systems/authentications/sign_in/sign_in_spec.rb @@ -38,7 +38,7 @@ submit_authentication_form(user.email, 'invalid') - expect(page).to have_text "Invalid Email or password." + expect(page).to have_text 'Invalid Email or password.' end end end @@ -49,7 +49,7 @@ def submit_authentication_form(email, password) within selectors[:auth_form] do fill_in selectors[:email_field], with: email fill_in selectors[:password_field], with: password - click_button "Log in" + click_button 'Log in' end end end From 52e825423a00dc70854a3cd1fdb8b5a0020bd7ee Mon Sep 17 00:00:00 2001 From: topnimble <90754900+topnimble@users.noreply.github.com> Date: Fri, 16 Jun 2023 15:10:02 +0700 Subject: [PATCH 26/27] Copy `.env.example` to `.env` --- .env.example | 6 ++++++ Dockerfile | 3 +++ 2 files changed, 9 insertions(+) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..a0b3aae --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +DOCKER_REGISTRY_HOST=docker.io +DOCKER_IMAGE=mosharaf13/google_scrapper_ruby +BRANCH_TAG=latest +PORT=80 +CI=true +TEST_RETRY=0 diff --git a/Dockerfile b/Dockerfile index ef63398..914a272 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,6 +52,9 @@ RUN if [ "$BUILD_ENV" = "test" ]; then \ WORKDIR $APP_HOME +# Copy ENV file +COPY .env.example .env + # Skip installing gem documentation RUN mkdir -p /usr/local/etc \ && { \ From b995dba70f77c5e8f68507105a01fce14d4d5933 Mon Sep 17 00:00:00 2001 From: topnimble <90754900+topnimble@users.noreply.github.com> Date: Fri, 16 Jun 2023 16:27:07 +0700 Subject: [PATCH 27/27] Enable `RAILS_SERVE_STATIC_FILES` --- .env.example | 1 + 1 file changed, 1 insertion(+) diff --git a/.env.example b/.env.example index a0b3aae..b754bc1 100644 --- a/.env.example +++ b/.env.example @@ -4,3 +4,4 @@ BRANCH_TAG=latest PORT=80 CI=true TEST_RETRY=0 +RAILS_SERVE_STATIC_FILES=true