Skip to content
Open
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
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DOCKER_REGISTRY_HOST=docker.io
DOCKER_IMAGE=mosharaf13/google_scrapper_ruby
BRANCH_TAG=latest
PORT=80
CI=true
TEST_RETRY=0
RAILS_SERVE_STATIC_FILES=true
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
&& { \
Expand Down
33 changes: 33 additions & 0 deletions app/views/devise/sessions/new.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<div class="container">
<h2 class="text-center">Log in</h2>

<div class="row justify-content-center">
<div class="col-lg-4">
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="field form-group">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, autocomplete: 'email', class: 'form-control' %>
</div>

<div class="field form-group mt-3">
<%= f.label :password %><br />
<%= f.password_field :password, autocomplete: 'current-password', class: 'form-control' %>
</div>

<% if devise_mapping.rememberable? %>
<div class="field form-group mt-3">
<%= f.check_box :remember_me, class: 'form-check-input' %>
<%= f.label :remember_me, class: 'form-check-label' %>
</div>
<% end %>

<div class="actions text-center mt-3">
<div class="d-flex justify-content-center">
<%= f.submit 'Log in', class: 'btn btn-primary m-1' %>
</div>
<%= render 'devise/shared/links' %>
</div>
<% end %>
</div>
</div>
</div>
6 changes: 0 additions & 6 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
<% if user_signed_in? %>
<div> Welcome <%= current_user.email %> </div>
<%= button_to 'Sign out', destroy_user_session_path, method: :delete %>
<% else %>
<%= button_to 'Sign in', new_user_session_path %>
<% end %>
<h1>
Welcome to the world of scrapping!!
</h1>
18 changes: 12 additions & 6 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>
</head>
<%= stylesheet_link_tag 'application', 'data-turbo-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbo-track': 'reload', defer: true %>
</head>

<body>
<p style="color: green"><%= notice %></p>
<p class="alert"><%= alert %></p>
<%= yield %>
<%= render 'shared/header' %>

<main class="flex-shrink-0">
<div class="container mt-5">
<%= render 'shared/flashes' %>

<%= yield %>
</div>
</main>
</body>
</html>
7 changes: 7 additions & 0 deletions app/views/shared/_flashes.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<% if notice %>
<p class="notice alert alert-info"><%= notice %></p>
<% end %>

<% if alert %>
<p class="alert alert-danger"><%= alert %></p>
<% end %>
14 changes: 14 additions & 0 deletions app/views/shared/_header.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<header class="p-3 text-bg-dark">
<div class="container">
<div class="d-flex flex-wrap align-items-center justify-content-center justify-content-lg-start">
<%= 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? %>
<div class="me-3"> Welcome <%= current_user.email %> </div>
<%= 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 %>
</div>
</div>
</header>
8 changes: 8 additions & 0 deletions spec/support/devise.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

RSpec.configure do |config|
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
2 changes: 2 additions & 0 deletions spec/support/system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions spec/support/user_authentication.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

def login_as_user(user = Fabricate(:user))
Comment thread
This conversation was marked as resolved.
login_as user
end
55 changes: 55 additions & 0 deletions spec/systems/authentications/sign_in/sign_in_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 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.build(: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.build(:user, password: 'password')

submit_authentication_form(user.email, 'invalid')

expect(page).to have_current_path(root_path)
end

it 'shows the error message' do
visit new_user_session_path
user = Fabricate.build(:user, password: 'password')

submit_authentication_form(user.email, 'invalid')

expect(page).to have_text 'Invalid Email or password.'
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 'Log in'
end
end
end
20 changes: 20 additions & 0 deletions spec/systems/authentications/sign_out/sign_out_spec.rb
Original file line number Diff line number Diff line change
@@ -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_user
visit root_path

click_link selectors[:sign_out_button]

expect(page).to have_current_path(root_path)
end
end