Skip to content

Commit

Permalink
Rails 5 upgrade.
Browse files Browse the repository at this point in the history
Upgraded rails 5 as well as some dependencies. Currently not all the tests pass.
  • Loading branch information
jsperezg committed Sep 1, 2020
1 parent 7c626a0 commit 9a118b7
Show file tree
Hide file tree
Showing 62 changed files with 462 additions and 305 deletions.
5 changes: 3 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ require: rubocop-rspec

AllCops:
TargetRubyVersion: 2.4.4
NewCops: disable
Exclude:
- 'db/migrate/*.rb'
- 'db/schema.rb'
- 'bin/*'

Metrics/LineLength:
Layout/LineLength:
Exclude:
- 'config/initializers/devise.rb'
Max: 150
Expand All @@ -21,7 +22,7 @@ Metrics/BlockLength:
- 'config/environments/*.rb'
- 'config/routes.rb'

Documentation:
Style/Documentation:
Enabled: false

RSpec/ExampleLength:
Expand Down
7 changes: 4 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.6'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 4.2', '>= 4.2.6'
gem 'rails', '~> 5.0'
# Use mysql as the database for Active Record
gem 'mysql2', '~> 0.4.0'
# Use SCSS for stylesheets
Expand All @@ -32,7 +32,7 @@ gem 'data-confirm-modal'
gem 'devise', '~> 4.7.1'
gem 'email_validator'
gem 'figaro'
gem 'filterrific', '~> 4.0.1'
gem 'filterrific', '~> 5.2.1'
gem 'jquery-rails'
gem 'jquery-turbolinks'
gem 'jquery-ui-rails'
Expand Down Expand Up @@ -77,7 +77,7 @@ group :development do
gem 'capistrano-rails', '~> 1.1'
gem 'capistrano-rbenv', '~> 2.0'

gem 'rubocop', require: false
gem 'rubocop'
gem 'rubocop-rspec'

# Access an IRB console on exception pages or by using <%= console %> in views
Expand All @@ -95,5 +95,6 @@ end

group :test do
gem 'database_cleaner'
gem 'rails-controller-testing'
gem 'simplecov', require: false
end
118 changes: 65 additions & 53 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,42 @@ GIT
GEM
remote: https://rubygems.org/
specs:
actionmailer (4.2.11.3)
actionpack (= 4.2.11.3)
actionview (= 4.2.11.3)
activejob (= 4.2.11.3)
actioncable (5.0.7.2)
actionpack (= 5.0.7.2)
nio4r (>= 1.2, < 3.0)
websocket-driver (~> 0.6.1)
actionmailer (5.0.7.2)
actionpack (= 5.0.7.2)
actionview (= 5.0.7.2)
activejob (= 5.0.7.2)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.5)
actionpack (4.2.11.3)
actionview (= 4.2.11.3)
activesupport (= 4.2.11.3)
rack (~> 1.6)
rack-test (~> 0.6.2)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-dom-testing (~> 2.0)
actionpack (5.0.7.2)
actionview (= 5.0.7.2)
activesupport (= 5.0.7.2)
rack (~> 2.0)
rack-test (~> 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (4.2.11.3)
activesupport (= 4.2.11.3)
actionview (5.0.7.2)
activesupport (= 5.0.7.2)
builder (~> 3.1)
erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (4.2.11.3)
activesupport (= 4.2.11.3)
globalid (>= 0.3.0)
activemodel (4.2.11.3)
activesupport (= 4.2.11.3)
builder (~> 3.1)
activerecord (4.2.11.3)
activemodel (= 4.2.11.3)
activesupport (= 4.2.11.3)
arel (~> 6.0)
activesupport (4.2.11.3)
i18n (~> 0.7)
activejob (5.0.7.2)
activesupport (= 5.0.7.2)
globalid (>= 0.3.6)
activemodel (5.0.7.2)
activesupport (= 5.0.7.2)
activerecord (5.0.7.2)
activemodel (= 5.0.7.2)
activesupport (= 5.0.7.2)
arel (~> 7.0)
activesupport (5.0.7.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
airbrussh (1.4.0)
sshkit (>= 1.6.1, != 1.7.0)
Expand All @@ -53,7 +56,7 @@ GEM
apartment-sidekiq (1.2.0)
apartment (>= 1.0)
sidekiq (>= 2.11)
arel (6.0.4)
arel (7.1.4)
ast (2.4.1)
axiom-types (0.1.1)
descendants_tracker (~> 0.0.4)
Expand Down Expand Up @@ -149,11 +152,11 @@ GEM
ffi (1.13.1)
figaro (1.2.0)
thor (>= 0.14.0, < 2)
filterrific (4.0.1)
filterrific (5.2.1)
globalid (0.4.2)
activesupport (>= 4.2.0)
hashie (4.1.0)
i18n (0.9.5)
i18n (1.8.5)
concurrent-ruby (~> 1.0)
i18n_data (0.10.0)
ice_nine (0.11.2)
Expand Down Expand Up @@ -186,6 +189,7 @@ GEM
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
method_source (1.0.0)
mime-types (3.3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2020.0512)
Expand All @@ -200,6 +204,7 @@ GEM
net-scp (3.0.0)
net-ssh (>= 2.6.5, < 7.0.0)
net-ssh (6.1.0)
nio4r (2.5.2)
nokogiri (1.10.10)
mini_portile2 (~> 2.4.0)
nprogress-rails (0.2.0.2)
Expand Down Expand Up @@ -237,35 +242,38 @@ GEM
prawn-table (0.2.2)
prawn (>= 1.3.0, < 3.0.0)
public_suffix (4.0.5)
rack (1.6.13)
rack (2.0.9)
rack-cors (1.0.6)
rack (>= 1.6.0)
rack-protection (2.0.8.1)
rack
rack-test (0.6.3)
rack (>= 1.0)
rails (4.2.11.3)
actionmailer (= 4.2.11.3)
actionpack (= 4.2.11.3)
actionview (= 4.2.11.3)
activejob (= 4.2.11.3)
activemodel (= 4.2.11.3)
activerecord (= 4.2.11.3)
activesupport (= 4.2.11.3)
bundler (>= 1.3.0, < 2.0)
railties (= 4.2.11.3)
sprockets-rails
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.9)
activesupport (>= 4.2.0, < 5.0)
nokogiri (~> 1.6)
rails-deprecated_sanitizer (>= 1.0.1)
rails (5.0.7.2)
actioncable (= 5.0.7.2)
actionmailer (= 5.0.7.2)
actionpack (= 5.0.7.2)
actionview (= 5.0.7.2)
activejob (= 5.0.7.2)
activemodel (= 5.0.7.2)
activerecord (= 5.0.7.2)
activesupport (= 5.0.7.2)
bundler (>= 1.3.0)
railties (= 5.0.7.2)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
actionview (>= 5.0.1.rc1)
activesupport (>= 5.0.1.rc1)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.3.0)
loofah (~> 2.3)
railties (4.2.11.3)
actionpack (= 4.2.11.3)
activesupport (= 4.2.11.3)
railties (5.0.7.2)
actionpack (= 5.0.7.2)
activesupport (= 5.0.7.2)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (3.0.0)
Expand Down Expand Up @@ -399,6 +407,9 @@ GEM
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
will_paginate (3.3.0)
will_paginate-bootstrap (1.0.2)
will_paginate (>= 3.0.3)
Expand Down Expand Up @@ -436,7 +447,7 @@ DEPENDENCIES
factory_bot_rails
faker
figaro
filterrific (~> 4.0.1)
filterrific (~> 5.2.1)
jbuilder (~> 2.0)
jquery-rails
jquery-turbolinks
Expand All @@ -450,7 +461,8 @@ DEPENDENCIES
prawn
prawn-table
rack-cors
rails (~> 4.2, >= 4.2.6)
rails (~> 5.0)
rails-controller-testing
rectify
rspec-rails (~> 3.0)
rspec-sidekiq
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def invoice_finished
invoice.apply_irpf(current_user)

# Iterate over finished tasks.
tasks = Task.retrieve_project_tasks(@project.id).where.not(finish_date: :nil)
tasks = Task.retrieve_project_tasks(@project.id).where.not(finish_date: nil)
tasks.each do |task|
task.invoice_timelogs_into(invoice)
end
Expand Down
4 changes: 4 additions & 0 deletions app/jobs/application_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class ApplicationJob < ActiveJob::Base
end
48 changes: 27 additions & 21 deletions app/jobs/renew_subscription_job.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class RenewSubscriptionJob < ActiveJob::Base
class RenewSubscriptionJob < ApplicationJob
include InvoicingNotifications

queue_as :urgent
Expand All @@ -24,7 +24,7 @@ def send_invoice(payment)
rescue StandardError => e
raise e
ensure
Appartment::Tenant.switch! unless Rails.env.test?
Apartment::Tenant.switch! unless Rails.env.test?
end
end

Expand Down Expand Up @@ -66,15 +66,7 @@ def find_or_create_customer(user)
if customer.nil?
customer = create_customer_for(user)
else
Customer.update_attributes!(
name: user.name,
address: user.address,
city: user.city,
postal_code: user.postal_code,
state: user.state,
contact_email: user.email,
contact_phone: user.phone_number
)
update_customer(customer, user)
end

customer
Expand All @@ -95,19 +87,33 @@ def create_customer_for(user)
)
end

def update_customer(customer, user)
customer.update_attributes!(
name: user.name,
address: user.address,
city: user.city,
postal_code: user.postal_code,
state: user.state,
contact_email: user.email,
contact_phone: user.phone_number
)
end

def find_or_create_service(plan)
service = Service.find_by(description: plan.description, active: true)
if service.nil?
service = Service.create!(
code: "S/#{Time.now.strftime('%Y%m%d')}/#{plan.months}",
description: plan.description,
vat_id: find_or_create_vat(plan.vat_rate).id,
unit_id: find_or_create_unit('Months').id,
price: plan.price
)
end
return service if service.present?

service
create_service(plan)
end

def create_service(plan)
Service.create!(
code: "S/#{Time.now.strftime('%Y%m%d')}/#{plan.months}",
description: plan.description,
vat_id: find_or_create_vat(plan.vat_rate).id,
unit_id: find_or_create_unit('Months').id,
price: plan.price
)
end

def find_or_create_vat(vat_rate)
Expand Down
5 changes: 5 additions & 0 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
2 changes: 1 addition & 1 deletion app/models/customer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# This model represents a customer.
class Customer < ActiveRecord::Base
class Customer < ApplicationRecord
filterrific(
default_filter_params: {
sorted_by: 'name_asc'
Expand Down
4 changes: 2 additions & 2 deletions app/models/delivery_note.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# Class represents a delivery note.
class DeliveryNote < ActiveRecord::Base
class DeliveryNote < ApplicationRecord
include SequenceGenerator

filterrific(
Expand All @@ -23,7 +23,7 @@ class DeliveryNote < ActiveRecord::Base
attr[:description].blank?
}, allow_destroy: true

validates :customer_id, presence: true
validates :customer, presence: true
validates :date, presence: true
validates :number, presence: true, uniqueness: true
validate :number_format
Expand Down
6 changes: 3 additions & 3 deletions app/models/delivery_note_detail.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

class DeliveryNoteDetail < ActiveRecord::Base
class DeliveryNoteDetail < ApplicationRecord
belongs_to :delivery_note, touch: true
belongs_to :service
belongs_to :invoice_detail
belongs_to :service, optional: true
belongs_to :invoice_detail, optional: true

validates :quantity, presence: true, numericality: { greater_than: 0 }
validates :price, presence: true, numericality: { greater_than: 0 }
Expand Down
Loading

0 comments on commit 9a118b7

Please sign in to comment.