Skip to content

Commit

Permalink
all-except stripe
Browse files Browse the repository at this point in the history
  • Loading branch information
Avneet Singh Malhotra committed Mar 6, 2018
1 parent e7e21c9 commit 041556a
Show file tree
Hide file tree
Showing 25 changed files with 1,115 additions and 58 deletions.
8 changes: 7 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ group :development, :test do
gem 'capybara', '~> 2.13'
gem 'selenium-webdriver', '~> 3.8.0'
gem 'rspec-rails', '~> 3.7'
gem 'figaro', '~> 1.1.1'
gem 'factory_bot_rails', '~> 4.8.2'

end

group :development do
Expand All @@ -69,11 +72,14 @@ 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 'simplecov', '~> 0.15.1', require: false
gem 'shoulda', '~> 3.5'
gem 'shoulda-callback-matchers', '~> 1.1', '>= 1.1.3'
gem 'shoulda-matchers', '~> 2.8.0'
gem 'rails-controller-testing', '~> 1.0.2'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
Expand Down
92 changes: 57 additions & 35 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
GEM
remote: https://rubygems.org/
specs:
actioncable (5.1.4)
actionpack (= 5.1.4)
actioncable (5.1.5)
actionpack (= 5.1.5)
nio4r (~> 2.0)
websocket-driver (~> 0.6.1)
actionmailer (5.1.4)
actionpack (= 5.1.4)
actionview (= 5.1.4)
activejob (= 5.1.4)
actionmailer (5.1.5)
actionpack (= 5.1.5)
actionview (= 5.1.5)
activejob (= 5.1.5)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (5.1.4)
actionview (= 5.1.4)
activesupport (= 5.1.4)
actionpack (5.1.5)
actionview (= 5.1.5)
activesupport (= 5.1.5)
rack (~> 2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (5.1.4)
activesupport (= 5.1.4)
actionview (5.1.5)
activesupport (= 5.1.5)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
Expand All @@ -29,16 +29,16 @@ GEM
activemodel (>= 4.1, < 6)
case_transform (>= 0.2)
jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
activejob (5.1.4)
activesupport (= 5.1.4)
activejob (5.1.5)
activesupport (= 5.1.5)
globalid (>= 0.3.6)
activemodel (5.1.4)
activesupport (= 5.1.4)
activerecord (5.1.4)
activemodel (= 5.1.4)
activesupport (= 5.1.4)
activemodel (5.1.5)
activesupport (= 5.1.5)
activerecord (5.1.5)
activemodel (= 5.1.5)
activesupport (= 5.1.5)
arel (~> 8.0)
activesupport (5.1.4)
activesupport (5.1.5)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
minitest (~> 5.1)
Expand All @@ -53,7 +53,7 @@ GEM
rack (>= 0.9.0)
bindex (0.5.0)
builder (3.2.3)
bullet (5.7.2)
bullet (5.7.3)
activesupport (>= 3.0.0)
uniform_notifier (~> 1.11.0)
byebug (10.0.0)
Expand Down Expand Up @@ -94,14 +94,19 @@ GEM
docile (1.1.5)
erubi (1.7.0)
execjs (2.7.0)
factory_bot (4.8.2)
activesupport (>= 3.0.0)
factory_bot_rails (4.8.2)
factory_bot (~> 4.8.2)
railties (>= 3.0.0)
faraday (0.14.0)
multipart-post (>= 1.2, < 3)
ffi (1.9.21)
ffi (1.9.22)
figaro (1.1.1)
thor (~> 0.14)
globalid (0.4.1)
activesupport (>= 4.2.0)
i18n (0.9.4)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
jbuilder (2.7.0)
activesupport (>= 4.2.0)
Expand Down Expand Up @@ -155,28 +160,32 @@ GEM
rack (2.0.4)
rack-test (0.8.2)
rack (>= 1.0, < 3)
rails (5.1.4)
actioncable (= 5.1.4)
actionmailer (= 5.1.4)
actionpack (= 5.1.4)
actionview (= 5.1.4)
activejob (= 5.1.4)
activemodel (= 5.1.4)
activerecord (= 5.1.4)
activesupport (= 5.1.4)
rails (5.1.5)
actioncable (= 5.1.5)
actionmailer (= 5.1.5)
actionpack (= 5.1.5)
actionview (= 5.1.5)
activejob (= 5.1.5)
activemodel (= 5.1.5)
activerecord (= 5.1.5)
activesupport (= 5.1.5)
bundler (>= 1.3.0)
railties (= 5.1.4)
railties (= 5.1.5)
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)
rails-footnotes (4.1.8)
rails (>= 3.2)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
railties (5.1.4)
actionpack (= 5.1.4)
activesupport (= 5.1.4)
railties (5.1.5)
actionpack (= 5.1.5)
activesupport (= 5.1.5)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
Expand Down Expand Up @@ -218,6 +227,14 @@ GEM
selenium-webdriver (3.8.0)
childprocess (~> 0.5)
rubyzip (~> 1.0)
shoulda (3.5.0)
shoulda-context (~> 1.0, >= 1.0.1)
shoulda-matchers (>= 1.4.1, < 3.0)
shoulda-callback-matchers (1.1.4)
activesupport (>= 3)
shoulda-context (1.2.2)
shoulda-matchers (2.8.0)
activesupport (>= 3.0.0)
simplecov (0.15.1)
docile (~> 1.1.0)
json (>= 1.8, < 3)
Expand Down Expand Up @@ -276,6 +293,7 @@ DEPENDENCIES
ckeditor (~> 4.1.3)
coffee-rails (~> 4.2)
delayed_job_active_record (~> 4.1.2)
factory_bot_rails (~> 4.8.2)
figaro (~> 1.1.1)
jbuilder (~> 2.5)
jquery-rails (~> 4.3.1)
Expand All @@ -287,10 +305,14 @@ DEPENDENCIES
paperclip (~> 5.1.0)
puma (~> 3.7)
rails (~> 5.1.4)
rails-controller-testing (~> 1.0.2)
rails-footnotes (~> 4.1.8)
rspec-rails (~> 3.7)
sass-rails (~> 5.0)
selenium-webdriver (~> 3.8.0)
shoulda (~> 3.5)
shoulda-callback-matchers (~> 1.1, >= 1.1.3)
shoulda-matchers (~> 2.8.0)
simplecov (~> 0.15.1)
state_machines (~> 0.5.0)
state_machines-activerecord (~> 0.5.0)
Expand Down
2 changes: 1 addition & 1 deletion 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 Down
4 changes: 2 additions & 2 deletions app/models/deal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class Deal < ApplicationRecord
with_options allow_blank: true do
validates :title, uniqueness: { case_sensitive: false }

validates :price, numericality: { greater_than_or_equal_to: ENV['minimum_price'].to_i }
validates :discount_price, numericality: { greater_than_or_equal_to: ENV['minimum_discount_price'].to_i }
validates :price, numericality: { greater_than_or_equal_to: ENV['minimum_price'].to_f }
validates :discount_price, numericality: { greater_than_or_equal_to: ENV['minimum_discount_price'].to_f }

validates :quantity, numericality: {
only_integer: true,
Expand Down
10 changes: 5 additions & 5 deletions app/models/line_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ class LineItem < ApplicationRecord
validates :quantity, :discount_price, :price, :loyalty_discount, :total_amount
end

validates :price, numericality: { greater_than_or_equal_to: ENV['minimum_price'].to_i }
validates :discount_price, numericality: { greater_than_or_equal_to: ENV['minimum_discount_price'].to_i }
validates :price, numericality: { greater_than_or_equal_to: ENV['minimum_price'].to_f }
validates :discount_price, numericality: { greater_than_or_equal_to: ENV['minimum_discount_price'].to_f }
validates :loyalty_discount, numericality: { greater_than_or_equal_to: ENV['minimum_loyalty_discount'] .to_i}

# ensure quantity less than or equal to deal.quantity
validate :ensure_quantity_available
validate :ensure_quantity_available, if: [:quantity, :deal]

validate :ensure_deal_not_bought_again_in_another_order
validate :ensure_deal_live
validate :ensure_deal_not_bought_again_in_another_order, if: [:order]
validate :ensure_deal_live, if: [:deal]

## CALLBACKS
before_save :update_loyalty_discount
Expand Down
23 changes: 16 additions & 7 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ class User < ApplicationRecord
}

validates :password, on: :update, if: :password_confirmation_present?
validates :password_confirmation, on: :create
end

validates :password, allow_blank: true, length: { minimum: 6 }

## CALLBACKLS
## CALLBACKS
before_update :clear_confirmed_token_sent_at, if: :confirmation_token_changed?
before_update :clear_password_reset_token_sent_at, if: :password_reset_token_changed?
after_commit :send_confrimation_instructions, on: :create
after_commit :send_confirmation_instructions, on: :create


def send_confrimation_instructions
def send_confirmation_instructions
generate_confirmation_token
UserMailer.confirmation_email(id, password).deliver_later
end
Expand All @@ -54,12 +55,16 @@ def generate_confirmation_token
end

def confirmation_token_expired?
return true if confirmation_token_sent_at.nil? || confirmation_token.nil?
if confirmation_token_sent_at.nil? || confirmation_token.nil?
return true
end
Time.current - confirmation_token_sent_at > CONFIRMATION_TOKEN_VALIDITY
end

def password_reset_token_expired?
return true if password_reset_token_sent_at.nil? || password_reset_token.nil?
if password_reset_token_sent_at.nil? || password_reset_token.nil?
return true
end
Time.current - password_reset_token_sent_at > PASSWORD_RESET_TOKEN_VALIDITY
end

Expand All @@ -80,11 +85,15 @@ def recently_used_address_id
private

def clear_confirmed_token_sent_at
self.confirmation_token_sent_at = nil if confirmation_token.nil?
if confirmation_token.nil?
self.confirmation_token_sent_at = nil
end
end

def clear_password_reset_token_sent_at
self.password_reset_token_sent_at = nil if password_reset_token.nil?
if password_reset_token.nil?
self.password_reset_token_sent_at = nil
end
end

def password_confirmation_present?
Expand Down
Binary file added spec/files/images/1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added spec/files/images/2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added spec/files/images/pic1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions spec/models/address_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require "rails_helper"

RSpec.describe Address, type: :model do

describe 'associations' do
it { is_expected.to have_many(:orders).dependent(:restrict_with_error) }
it { is_expected.to belong_to(:user) }
end

describe 'validations' do
context 'house_number' do
it { is_expected.to validate_presence_of(:house_number) }
it { is_expected.to validate_uniqueness_of(:house_number).scoped_to(:street, :city, :pincode) }
end

context 'street' do
it { is_expected.to validate_presence_of(:street) }
end

context 'city' do
it { is_expected.to validate_presence_of(:city) }
end

context 'state' do
it { is_expected.to validate_presence_of(:state) }
end

context 'country' do
it { is_expected.to validate_presence_of(:country) }
end

context 'pincode' do
it { is_expected.to validate_presence_of(:pincode) }
it { is_expected.to validate_numericality_of(:pincode).only_integer.allow_nil }
end

describe 'public instance methods' do
context '#pretty_errors' do
it { is_expected.to respond_to(:pretty_errors) }
end

context '#full_address' do
it { is_expected.to respond_to(:full_address) }
end
end
end
end
Loading

0 comments on commit 041556a

Please sign in to comment.