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

Minitest of controllers #46

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ db/schema.rb

# Ignore application configuration
/config/application.yml

coverage/*
8 changes: 7 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ group :development, :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '~> 2.13'
gem 'selenium-webdriver', '~> 3.8.0'
gem 'figaro', '~> 1.1.1'
end

group :development do
Expand All @@ -68,7 +69,12 @@ group :development do
gem 'better_errors', '~> 2.4.0'
gem 'bullet', '~> 5.7.0'
gem 'rails-footnotes', '~> 4.1.8'
gem 'figaro', '~> 1.1.1'
end

group :test do
gem 'minitest-reporters', '~> 1.1.19'
gem 'simplecov', '~> 0.15.1'
gem 'rails-controller-testing', '~> 1.0.2'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
Expand Down
55 changes: 38 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ GEM
tzinfo (~> 1.1)
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
ansi (1.5.0)
arel (8.0.0)
bcrypt (3.1.11)
better_errors (2.4.0)
Expand All @@ -53,11 +54,11 @@ GEM
rack (>= 0.9.0)
bindex (0.5.0)
builder (3.2.3)
bullet (5.7.1)
bullet (5.7.2)
activesupport (>= 3.0.0)
uniform_notifier (~> 1.11.0)
byebug (9.1.0)
capybara (2.17.0)
byebug (10.0.0)
capybara (2.18.0)
addressable
mini_mime (>= 0.1.3)
nokogiri (>= 1.3.3)
Expand All @@ -69,7 +70,7 @@ GEM
childprocess (0.8.0)
ffi (~> 1.0, >= 1.0.11)
chronic (0.10.2)
ckeditor (4.1.3)
ckeditor (4.1.6)
cocaine
orm_adapter (~> 0.5.0)
climate_control (0.2.0)
Expand All @@ -90,16 +91,17 @@ GEM
delayed_job_active_record (4.1.2)
activerecord (>= 3.0, < 5.2)
delayed_job (>= 3.0, < 5)
docile (1.1.5)
erubi (1.7.0)
execjs (2.7.0)
faraday (0.13.1)
faraday (0.14.0)
multipart-post (>= 1.2, < 3)
ffi (1.9.18)
ffi (1.9.21)
figaro (1.1.1)
thor (~> 0.14)
globalid (0.4.1)
activesupport (>= 4.2.0)
i18n (0.9.1)
i18n (0.9.4)
concurrent-ruby (~> 1.0)
jbuilder (2.7.0)
activesupport (>= 4.2.0)
Expand All @@ -110,6 +112,7 @@ GEM
thor (>= 0.14, < 2.0)
jquery-ui-rails (6.0.1)
railties (>= 3.2.16)
json (2.1.0)
jsonapi-renderer (0.2.0)
launchy (2.4.3)
addressable (~> 2.3)
Expand All @@ -120,7 +123,7 @@ GEM
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
loofah (2.1.1)
loofah (2.2.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.0)
Expand All @@ -132,13 +135,18 @@ GEM
mimemagic (0.3.2)
mini_mime (1.0.0)
mini_portile2 (2.3.0)
minitest (5.11.1)
multi_json (1.12.2)
minitest (5.11.3)
minitest-reporters (1.1.19)
ansi
builder
minitest (>= 5.0)
ruby-progressbar
multi_json (1.13.1)
multipart-post (2.0.0)
mysql2 (0.4.10)
nested_form (0.3.2)
nio4r (2.2.0)
nokogiri (1.8.1)
nokogiri (1.8.2)
mini_portile2 (~> 2.3.0)
orm_adapter (0.5.0)
paperclip (5.1.0)
Expand All @@ -147,9 +155,9 @@ GEM
cocaine (~> 0.5.5)
mime-types
mimemagic (~> 0.3.0)
public_suffix (3.0.1)
puma (3.11.0)
rack (2.0.3)
public_suffix (3.0.2)
puma (3.11.2)
rack (2.0.4)
rack-test (0.8.2)
rack (>= 1.0, < 3)
rails (5.1.4)
Expand All @@ -164,6 +172,10 @@ GEM
bundler (>= 1.3.0)
railties (= 5.1.4)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.2)
actionpack (~> 5.x, >= 5.0.1)
actionview (~> 5.x, >= 5.0.1)
activesupport (~> 5.x)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
Expand All @@ -182,6 +194,7 @@ GEM
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
ref (2.0.0)
ruby-progressbar (1.9.0)
ruby_dep (1.5.0)
rubyzip (1.2.1)
sass (3.5.5)
Expand All @@ -198,6 +211,11 @@ GEM
selenium-webdriver (3.8.0)
childprocess (~> 0.5)
rubyzip (~> 1.0)
simplecov (0.15.1)
docile (~> 1.1.0)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
sprockets (3.7.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
Expand All @@ -212,17 +230,17 @@ GEM
state_machines-activerecord (0.5.0)
activerecord (>= 4.1, < 5.2)
state_machines-activemodel (>= 0.5.0)
stripe (3.9.1)
stripe (3.9.2)
faraday (~> 0.10)
therubyracer (0.12.3)
libv8 (~> 3.16.14.15)
ref
thor (0.20.0)
thread_safe (0.3.6)
tilt (2.0.8)
tzinfo (1.2.4)
tzinfo (1.2.5)
thread_safe (~> 0.1)
uglifier (4.1.3)
uglifier (4.1.6)
execjs (>= 0.3.0, < 3)
uniform_notifier (1.11.0)
web-console (3.5.1)
Expand Down Expand Up @@ -257,14 +275,17 @@ DEPENDENCIES
jquery-ui-rails (~> 6.0.1)
letter_opener (~> 1.4.1)
listen (>= 3.0.5, < 3.2)
minitest-reporters (~> 1.1.19)
mysql2 (>= 0.3.18, < 0.5)
nested_form (~> 0.3.2)
paperclip (~> 5.1.0)
puma (~> 3.7)
rails (~> 5.1.4)
rails-controller-testing (~> 1.0.2)
rails-footnotes (~> 4.1.8)
sass-rails (~> 5.0)
selenium-webdriver (~> 3.8.0)
simplecov (~> 0.15.1)
state_machines (~> 0.5.0)
state_machines-activerecord (~> 0.5.0)
stripe (~> 3.9.1)
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/addresses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class AddressesController < ApplicationController

before_action :ensure_current_order_present
before_action :ensure_checkout_allowed
before_action :update_current_order_state, only: [:new]
before_action :update_current_order_state, only: [:new, :create, :associate_address]
before_action :get_current_user_associated_addresses, only: [:new, :create]
before_action :get_address, only: [:associate_address]

Expand Down Expand Up @@ -41,7 +41,9 @@ def address_params

def get_address
@address = Address.find_by(id: params[:current_user][:recently_used_address_id])
render_404 unless @address.present?
unless @address.present?
render_404
end
end

def update_current_order_state
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/admin/deals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def update_deal_params

def set_deal
@deal = Deal.find_by(id: params[:id])
render_404 unless @deal.present?
unless @deal.present?
render_404
end
end
end
8 changes: 6 additions & 2 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def update

def set_user
@user = User.find_by(id: params[:id])
render_404 unless @user.present?
unless @user.present?
render_404
end
end

def new_user_params
Expand All @@ -51,6 +53,8 @@ def update_user_params
end

def ensure_not_admin
redirect_to admin_users_url, alert: t(:not_authorized, scope: [:flash, :alert]) if @user.admin?
if @user.admin?
redirect_to admin_users_url, alert: t(:not_authorized, scope: [:flash, :alert])
end
end
end
6 changes: 4 additions & 2 deletions app/controllers/confirmations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def new
end

def create
@user.send_confrimation_instructions
@user.send_confirmation_instructions
redirect_to login_url, notice: t(:confirmation_email_sent, scope: [:flash, :notice])
end

Expand All @@ -36,7 +36,9 @@ def ensure_not_confirmed

def fetch_user_from_confirmation_token
@user = User.find_by(confirmation_token: params[:confirmation_token])
render_404 if @user.nil?
if @user.nil?
render_404
end
end

def ensure_confirmation_token_validity
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/deals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ def show

def set_deal
@deal = Deal.find_by(id: params[:id])
render_404 unless @deal.present?
unless @deal.present?
render_404
end
end

def get_deals
Expand Down
8 changes: 6 additions & 2 deletions app/controllers/line_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ def update

def get_deal
@deal = Deal.find_by(id: params[:deal_id])
redirect_to root_path, alert: I18n.t(:deal_cannot_be_added_to_cart, scope: [:flash, :alert]) unless @deal.present?
unless @deal.present?
redirect_to root_path, alert: I18n.t(:deal_cannot_be_added_to_cart, scope: [:flash, :alert])
end
end

def get_line_item
@line_item = LineItem.find_by(id: params[:id])
render_404 unless @line_item.present?
unless @line_item.present?
render_404
end
end

def update_params
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def index
def cancel
begin
@order.cancelled_by!(current_user)
flash[:success] = I18n.t(:order_successfully_cancelled, scope: [:flash, :notice])
flash[:notice] = I18n.t(:order_successfully_cancelled, scope: [:flash, :notice])
rescue => e
flash[:alert] = e.message
end
Expand All @@ -37,7 +37,9 @@ def cancel

def get_order
@order = current_user.orders.find_by(invoice_number: params[:invoice_number])
render_404 unless @order.present?
unless @order.present?
render_404
end
end

end
4 changes: 3 additions & 1 deletion app/controllers/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ def fetch_user

def fetch_user_from_password_reset_token
@user = User.find_by(password_reset_token: params[:password_reset_token])
render_404 if @user.nil?
if @user.nil?
render_404
end
end

def ensure_password_reset_token_validity
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/payments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def new
def create
@payment = current_order.payments.build
create_stripe_payment
redirect_to order_path(@payment.order), success: I18n.t(:order_placed_successfully, scope: [:flash, :success])
redirect_to order_path(@payment.order), notice: I18n.t(:order_placed_successfully, scope: [:flash, :notice]) and return
end


Expand Down
4 changes: 3 additions & 1 deletion app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def update_user_params

def set_user
@user = User.find_by(id: params[:id])
render_404 if @user.try(:id) != current_user.id
if @user.try(:id) != current_user.id
render_404
end
end

end
7 changes: 6 additions & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ def new

def create
if @user.try(:authenticate, params[:user][:password])
create_remember_me_cookie if params[:remember_me].present?
if params[:remember_me].present?
create_remember_me_cookie
end
session[:user_id] = @user.id

flash[:notice] = t(:login_successfull, scope: [:flash, :notice])
Expand All @@ -32,6 +34,9 @@ def destroy

def fetch_user
@user = User.find_by(email: params[:user][:email])
if @user.nil?
redirect_to login_url, alert: t(:invalid_email_or_password, scope: [:flash, :alert])
end
end

def ensure_user_confirmed
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/controllers/rememberable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Controllers::Rememberable
def create_remember_me_cookie
cookies.encrypted[:remember_me] = {
value: @user.remember_me_token,
expires: Date.current + REMEMBER_ME_COOKIE_VALIDITY_DURATION,
expires: Time.current + REMEMBER_ME_COOKIE_VALIDITY_DURATION,
domain: request.domain
}
end
Expand Down
5 changes: 4 additions & 1 deletion app/models/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ class Address < ApplicationRecord

validates :pincode, numericality: {
only_integer: true,
greater_than: 0,
allow_blank: true }

validates :house_number, uniqueness: { scope: [:street, :city, :pincode] }
validates :house_number, uniqueness: {
scope: [:street, :city, :pincode],
case_sensitive: false }

def pretty_errors
errors.full_messages.join("<br>")
Expand Down
Loading