From 1b17f894741d32bd9e26416e10b7815ad880626d Mon Sep 17 00:00:00 2001 From: Luca Tironi Date: Sun, 31 Jan 2016 17:42:08 +0100 Subject: [PATCH 1/9] Update to rails 5 beta 1.1 --- .rubocop.yml | 1 - Gemfile | 9 ++++++- bin/bundle | 3 +++ bin/rails | 10 +++---- bin/rake | 5 ++++ bin/rspec | 3 ++- lib/primegap/core/version.rb | 3 ++- primegap-core.gemspec | 11 ++++---- spec/dummy/config/application.rb | 10 ++----- spec/dummy/config/boot.rb | 3 +-- spec/dummy/config/environments/development.rb | 27 ++++++++++++++----- spec/dummy/config/environments/production.rb | 25 +++++++++-------- spec/dummy/config/environments/test.rb | 8 +++--- ...e_record_belongs_to_required_by_default.rb | 5 ++++ .../application_controller_renderer.rb | 6 +++++ spec/dummy/config/initializers/assets.rb | 2 +- .../initializers/callback_terminator.rb | 5 ++++ .../config/initializers/cookies_serializer.rb | 1 + spec/dummy/config/initializers/cors.rb | 16 +++++++++++ .../request_forgery_protection.rb | 4 +++ .../config/initializers/wrap_parameters.rb | 4 +-- spec/models/customer_spec.rb | 8 +++--- spec/models/user_spec.rb | 8 +++--- 23 files changed, 122 insertions(+), 55 deletions(-) create mode 100755 bin/bundle create mode 100644 spec/dummy/config/initializers/active_record_belongs_to_required_by_default.rb create mode 100644 spec/dummy/config/initializers/application_controller_renderer.rb create mode 100644 spec/dummy/config/initializers/callback_terminator.rb create mode 100644 spec/dummy/config/initializers/cors.rb create mode 100644 spec/dummy/config/initializers/request_forgery_protection.rb diff --git a/.rubocop.yml b/.rubocop.yml index 2d878b5..83dfdf1 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -8,4 +8,3 @@ AllCops: Exclude: - db/**/* - spec/dummy/db/**/* - - bin/rspec diff --git a/Gemfile b/Gemfile index 8ae2e06..3c59703 100644 --- a/Gemfile +++ b/Gemfile @@ -3,4 +3,11 @@ source 'https://rubygems.org' # Specify your gem's dependencies in primegap-core.gemspec gemspec -gem 'codeclimate-test-reporter', group: :test, require: nil +group :test do + gem 'codeclimate-test-reporter', require: nil + gem 'rspec-expectations', github: 'rspec/rspec-expectations', branch: 'master' + gem 'rspec-mocks', github: 'rspec/rspec-mocks', branch: 'master' + gem 'rspec-support', github: 'rspec/rspec-support', branch: 'master' + gem 'rspec-core', github: 'rspec/rspec-core', branch: 'master' + gem 'rspec-rails', github: 'rspec/rspec-rails', branch: 'master' +end diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 0000000..66e9889 --- /dev/null +++ b/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails index e32c996..aa5a47b 100755 --- a/bin/rails +++ b/bin/rails @@ -1,12 +1,10 @@ #!/usr/bin/env ruby -# This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application. +# This command will automatically be run when you run "rails" with Rails 5 gems installed from the root of your application. +APP_PATH = File.expand_path('../../spec/dummy/config/application', __FILE__) ENGINE_ROOT = File.expand_path('../..', __FILE__) ENGINE_PATH = File.expand_path('../../lib/primegap/core/engine', __FILE__) - -# Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) - +require_relative '../spec/dummy/config/boot' require 'rails/all' +require 'rails/commands' require 'rails/engine/commands' diff --git a/bin/rake b/bin/rake index 0a696db..302640d 100755 --- a/bin/rake +++ b/bin/rake @@ -1,4 +1,9 @@ #!/usr/bin/env ruby +begin + load File.expand_path('../spring', __FILE__) +rescue LoadError => e + raise unless e.message.include?('spring') +end require_relative '../spec/dummy/config/boot' require 'rake' Rake.application.run diff --git a/bin/rspec b/bin/rspec index dde2557..6e67092 100755 --- a/bin/rspec +++ b/bin/rspec @@ -1,7 +1,8 @@ #!/usr/bin/env ruby begin load File.expand_path('../spring', __FILE__) -rescue LoadError +rescue LoadError => e + raise unless e.message.include?('spring') end require 'bundler/setup' load Gem.bin_path('rspec-core', 'rspec') diff --git a/lib/primegap/core/version.rb b/lib/primegap/core/version.rb index 264c316..2393c87 100644 --- a/lib/primegap/core/version.rb +++ b/lib/primegap/core/version.rb @@ -1,5 +1,6 @@ +# frozen_string_literal: true module Primegap module Core - VERSION = '0.1.0' + VERSION = '0.1.0'.freeze end end diff --git a/primegap-core.gemspec b/primegap-core.gemspec index 17d120d..0508ea3 100644 --- a/primegap-core.gemspec +++ b/primegap-core.gemspec @@ -17,19 +17,18 @@ Gem::Specification.new do |spec| spec.test_files = Dir['spec/**/*'] # Rails dependencies - spec.add_dependency 'activerecord', '~> 4.2.4' - spec.add_dependency 'actionmailer', '~> 4.2.4' + spec.add_dependency 'railties', '>= 5.0.0.beta1.1' + spec.add_dependency 'activerecord', '>= 5.0.0.beta1.1' + spec.add_dependency 'actionmailer', '>= 5.0.0.beta1.1' # Other dependecies spec.add_dependency 'bcrypt', '~> 3.1.7' - spec.add_dependency 'has_secure_token' # Development/Test dependencies spec.add_development_dependency 'sqlite3' - spec.add_development_dependency 'bundler', '~> 1.10' - spec.add_development_dependency 'rake', '~> 10.0' + spec.add_development_dependency 'bundler', '~> 1.11' + spec.add_development_dependency 'rake', '~> 10.5' spec.add_development_dependency 'rubocop' - spec.add_development_dependency 'rspec-rails', '~> 3.3' spec.add_development_dependency 'shoulda-matchers', '~> 3.0' end diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb index 9d176c4..463f9b9 100644 --- a/spec/dummy/config/application.rb +++ b/spec/dummy/config/application.rb @@ -4,6 +4,8 @@ require 'active_record/railtie' require 'action_mailer/railtie' +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) require 'primegap/core' @@ -13,14 +15,6 @@ class Application < Rails::Application # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. - # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. - # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. - # config.time_zone = 'Central Time (US & Canada)' - - # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. - # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] - # config.i18n.default_locale = :de - # Do not swallow errors in after_commit/after_rollback callbacks. config.active_record.raise_in_transactional_callbacks = true end diff --git a/spec/dummy/config/boot.rb b/spec/dummy/config/boot.rb index 6266cfc..dd9050c 100644 --- a/spec/dummy/config/boot.rb +++ b/spec/dummy/config/boot.rb @@ -1,5 +1,4 @@ -# Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__) -require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) +require 'bundler/setup' # Set up gems listed in the Gemfile. $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__) diff --git a/spec/dummy/config/environments/development.rb b/spec/dummy/config/environments/development.rb index b55e214..351331c 100644 --- a/spec/dummy/config/environments/development.rb +++ b/spec/dummy/config/environments/development.rb @@ -9,9 +9,20 @@ # Do not eager load code on boot. config.eager_load = false - # Show full error reports and disable caching. - config.consider_all_requests_local = true - config.action_controller.perform_caching = false + # Show full error reports. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + if Rails.root.join('tmp/caching-dev.txt').exist? + config.action_controller.perform_caching = true + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => 'public, max-age=172800' + } + else + config.action_controller.perform_caching = false + config.cache_store = :null_store + end # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false @@ -25,17 +36,21 @@ # Debug mode disables concatenation and preprocessing of assets. # This option may cause significant delays in view rendering with a large # number of complex assets. - config.assets.debug = true + # config.assets.debug = true # Asset digests allow you to set far-future HTTP expiration dates on all assets, # yet still be able to expire them through the digest params. - config.assets.digest = true + # config.assets.digest = true # Adds additional error checking when serving assets at runtime. # Checks for improperly declared sprockets dependencies. # Raises helpful error messages. - config.assets.raise_runtime_errors = true + # config.assets.raise_runtime_errors = true # Raises error for missing translations # config.action_view.raise_on_missing_translations = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + # config.file_watcher = ActiveSupport::EventedFileUpdateChecker end diff --git a/spec/dummy/config/environments/production.rb b/spec/dummy/config/environments/production.rb index 5c1b32e..220d042 100644 --- a/spec/dummy/config/environments/production.rb +++ b/spec/dummy/config/environments/production.rb @@ -14,15 +14,9 @@ config.consider_all_requests_local = false config.action_controller.perform_caching = true - # Enable Rack::Cache to put a simple HTTP cache in front of your application - # Add `rack-cache` to your Gemfile before enabling this. - # For large-scale production use, consider using a caching reverse proxy like - # NGINX, varnish or squid. - # config.action_dispatch.rack_cache = true - # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? # Compress JavaScripts and CSS. config.assets.js_compressor = :uglifier @@ -37,10 +31,17 @@ # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + # Action Cable endpoint configuration + # config.action_cable.url = 'wss://example.com/cable' + # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true @@ -49,16 +50,18 @@ config.log_level = :debug # Prepend all log lines with the following tags. - # config.log_tags = [ :subdomain, :uuid ] + # config.log_tags = [ :subdomain, :request_id ] # Use a different logger for distributed setups. - # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + # require 'syslog/logger' + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') # Use a different cache store in production. # config.cache_store = :mem_cache_store - # Enable serving of images, stylesheets, and JavaScripts from an asset server. - # config.action_controller.asset_host = 'http://assets.example.com' + # Use a real queuing backend for Active Job (and separate queues per environment) + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "primegap_#{Rails.env}" # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. diff --git a/spec/dummy/config/environments/test.rb b/spec/dummy/config/environments/test.rb index 1c19f08..1f90453 100644 --- a/spec/dummy/config/environments/test.rb +++ b/spec/dummy/config/environments/test.rb @@ -12,9 +12,11 @@ # preloads Rails for running tests, you may have to set it to true. config.eager_load = false - # Configure static file server for tests with Cache-Control for performance. - config.serve_static_files = true - config.static_cache_control = 'public, max-age=3600' + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + 'Cache-Control' => 'public, max-age=3600' + } # Show full error reports and disable caching. config.consider_all_requests_local = true diff --git a/spec/dummy/config/initializers/active_record_belongs_to_required_by_default.rb b/spec/dummy/config/initializers/active_record_belongs_to_required_by_default.rb new file mode 100644 index 0000000..78f4530 --- /dev/null +++ b/spec/dummy/config/initializers/active_record_belongs_to_required_by_default.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. + +# Require `belongs_to` associations by default. This is a new Rails 5.0 default, +# so introduced as a config to ensure apps made with earlier versions of Rails aren't affected when upgrading. +Rails.application.config.active_record.belongs_to_required_by_default = true diff --git a/spec/dummy/config/initializers/application_controller_renderer.rb b/spec/dummy/config/initializers/application_controller_renderer.rb new file mode 100644 index 0000000..51639b6 --- /dev/null +++ b/spec/dummy/config/initializers/application_controller_renderer.rb @@ -0,0 +1,6 @@ +# Be sure to restart your server when you modify this file. + +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) diff --git a/spec/dummy/config/initializers/assets.rb b/spec/dummy/config/initializers/assets.rb index 01ef3e6..ff2d229 100644 --- a/spec/dummy/config/initializers/assets.rb +++ b/spec/dummy/config/initializers/assets.rb @@ -1,7 +1,7 @@ # Be sure to restart your server when you modify this file. # Version of your assets, change this if you want to expire all your assets. -Rails.application.config.assets.version = '1.0' +# Rails.application.config.assets.version = '1.0' # Add additional assets to the asset load path # Rails.application.config.assets.paths << Emoji.images_path diff --git a/spec/dummy/config/initializers/callback_terminator.rb b/spec/dummy/config/initializers/callback_terminator.rb new file mode 100644 index 0000000..0b718aa --- /dev/null +++ b/spec/dummy/config/initializers/callback_terminator.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. + +# Do not halt callback chains when a callback returns false. This is a new Rails 5.0 default, +# so introduced as a config to ensure apps made with earlier versions of Rails aren't affected when upgrading. +ActiveSupport.halt_callback_chains_on_return_false = false diff --git a/spec/dummy/config/initializers/cookies_serializer.rb b/spec/dummy/config/initializers/cookies_serializer.rb index 7f70458..9332925 100644 --- a/spec/dummy/config/initializers/cookies_serializer.rb +++ b/spec/dummy/config/initializers/cookies_serializer.rb @@ -1,3 +1,4 @@ # Be sure to restart your server when you modify this file. +# This is a new Rails 5.0 default, so introduced as a config to ensure apps made with earlier versions of Rails aren't affected when upgrading. Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/spec/dummy/config/initializers/cors.rb b/spec/dummy/config/initializers/cors.rb new file mode 100644 index 0000000..3b1c1b5 --- /dev/null +++ b/spec/dummy/config/initializers/cors.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Avoid CORS issues when API is called from the frontend app. +# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests. + +# Read more: https://github.com/cyu/rack-cors + +# Rails.application.config.middleware.insert_before 0, Rack::Cors do +# allow do +# origins 'example.com' +# +# resource '*', +# headers: :any, +# methods: [:get, :post, :put, :patch, :delete, :options, :head] +# end +# end diff --git a/spec/dummy/config/initializers/request_forgery_protection.rb b/spec/dummy/config/initializers/request_forgery_protection.rb new file mode 100644 index 0000000..3eab78a --- /dev/null +++ b/spec/dummy/config/initializers/request_forgery_protection.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Enable origin-checking CSRF mitigation. +Rails.application.config.action_controller.forgery_protection_origin_check = true diff --git a/spec/dummy/config/initializers/wrap_parameters.rb b/spec/dummy/config/initializers/wrap_parameters.rb index 33725e9..bbfc396 100644 --- a/spec/dummy/config/initializers/wrap_parameters.rb +++ b/spec/dummy/config/initializers/wrap_parameters.rb @@ -5,10 +5,10 @@ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do - wrap_parameters format: [:json] if respond_to?(:wrap_parameters) + wrap_parameters format: [:json] end # To enable root element in JSON for ActiveRecord objects. # ActiveSupport.on_load(:active_record) do -# self.include_root_in_json = true +# self.include_root_in_json = true # end diff --git a/spec/models/customer_spec.rb b/spec/models/customer_spec.rb index 1db9a4e..b6fc77e 100644 --- a/spec/models/customer_spec.rb +++ b/spec/models/customer_spec.rb @@ -20,22 +20,24 @@ end describe '#split_full_name' do + let(:company) { Company.create(name: 'Joy Inc.') } + context 'with last_name' do - let(:subject) { Customer.create(full_name: 'Doe') } + let(:subject) { Customer.create(full_name: 'Doe', company_id: company.id) } it { expect(subject.first_name).to be_nil } it { expect(subject.last_name).to eq 'Doe' } end context 'with first_name and last_name' do - let(:subject) { Customer.create(full_name: 'John Doe') } + let(:subject) { Customer.create(full_name: 'John Doe', company_id: company.id) } it { expect(subject.first_name).to eq 'John' } it { expect(subject.last_name).to eq 'Doe' } end context 'with first_name, middle_name and last_name' do - let(:subject) { Customer.create(full_name: 'John F. Doe') } + let(:subject) { Customer.create(full_name: 'John F. Doe', company_id: company.id) } it { expect(subject.first_name).to eq 'John F.' } it { expect(subject.last_name).to eq 'Doe' } diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 69f63e6..a6140ff 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -21,11 +21,13 @@ end describe 'has secure password' do + let(:company) { Company.create(name: 'Joy Inc.') } + it { is_expected.to have_secure_password } it { is_expected.to validate_length_of(:password) } - it { expect(User.new(email: 'user@email.com', password: nil).save).to be_falsey } - it { expect(User.new(email: 'user@email.com', password: 'foo').save).to be_falsey } - it { expect(User.new(email: 'user@email.com', password: 'af3714ff0ffae').save).to be_truthy } + it { expect(User.new(email: 'user@email.com', password: nil, company_id: company.id).save).to be_falsey } + it { expect(User.new(email: 'user@email.com', password: 'foo', company_id: company.id).save).to be_falsey } + it { expect(User.new(email: 'user@email.com', password: 'af3714ff0ffae', company_id: company.id).save).to be_truthy } end end From f019b27addbcd422a42b03894f877b95eebd6128 Mon Sep 17 00:00:00 2001 From: Luca Tironi Date: Sun, 31 Jan 2016 17:42:32 +0100 Subject: [PATCH 2/9] Update models to inherit from ApplicationRecord --- app/models/application_record.rb | 3 +++ app/models/authentication_token.rb | 4 +--- app/models/authentication_tokens/scopes.rb | 0 app/models/company.rb | 2 +- app/models/customer.rb | 2 +- app/models/token_issuer.rb | 6 +++--- app/models/user.rb | 2 +- 7 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 app/models/application_record.rb create mode 100644 app/models/authentication_tokens/scopes.rb diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 0000000..10a4cba --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/authentication_token.rb b/app/models/authentication_token.rb index f6bdbe4..37920d0 100644 --- a/app/models/authentication_token.rb +++ b/app/models/authentication_token.rb @@ -1,6 +1,4 @@ -require 'has_secure_token' - -class AuthenticationToken < ActiveRecord::Base +class AuthenticationToken < ApplicationRecord include AuthenticationTokens::Associations has_secure_token :body diff --git a/app/models/authentication_tokens/scopes.rb b/app/models/authentication_tokens/scopes.rb new file mode 100644 index 0000000..e69de29 diff --git a/app/models/company.rb b/app/models/company.rb index 035eee5..add0f1c 100644 --- a/app/models/company.rb +++ b/app/models/company.rb @@ -1,4 +1,4 @@ -class Company < ActiveRecord::Base +class Company < ApplicationRecord include Companies::Associations include Companies::Validations end diff --git a/app/models/customer.rb b/app/models/customer.rb index 052f0b3..3356565 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -1,4 +1,4 @@ -class Customer < ActiveRecord::Base +class Customer < ApplicationRecord include Customers::Associations include Customers::Validations diff --git a/app/models/token_issuer.rb b/app/models/token_issuer.rb index 7fbb5d1..59f0fc3 100644 --- a/app/models/token_issuer.rb +++ b/app/models/token_issuer.rb @@ -42,9 +42,9 @@ def find_token(resource, token_from_headers) def purge_old_tokens(resource) resource.authentication_tokens - .order(last_used_at: :desc) - .offset(maximum_tokens_per_user) - .destroy_all + .order(last_used_at: :desc) + .offset(maximum_tokens_per_user) + .destroy_all end private diff --git a/app/models/user.rb b/app/models/user.rb index ba1d013..64d6a66 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,4 @@ -class User < ActiveRecord::Base +class User < ApplicationRecord include Users::Associations include Users::Validations From 5bdf32109502593d88446f78525f5b1a936eafbe Mon Sep 17 00:00:00 2001 From: Luca Tironi Date: Tue, 2 Feb 2016 08:15:49 +0100 Subject: [PATCH 3/9] Update to rails 5 beta 2 --- primegap-core.gemspec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/primegap-core.gemspec b/primegap-core.gemspec index 0508ea3..4d875da 100644 --- a/primegap-core.gemspec +++ b/primegap-core.gemspec @@ -17,9 +17,9 @@ Gem::Specification.new do |spec| spec.test_files = Dir['spec/**/*'] # Rails dependencies - spec.add_dependency 'railties', '>= 5.0.0.beta1.1' - spec.add_dependency 'activerecord', '>= 5.0.0.beta1.1' - spec.add_dependency 'actionmailer', '>= 5.0.0.beta1.1' + spec.add_dependency 'railties', '>= 5.0.0.beta2' + spec.add_dependency 'activerecord', '>= 5.0.0.beta2' + spec.add_dependency 'actionmailer', '>= 5.0.0.beta2' # Other dependecies spec.add_dependency 'bcrypt', '~> 3.1.7' From 401ca272eddf478582e24101206c722bee5433a5 Mon Sep 17 00:00:00 2001 From: Luca Tironi Date: Tue, 2 Feb 2016 08:16:43 +0100 Subject: [PATCH 4/9] Remove auto validation of belongs_to associations --- .../active_record_belongs_to_required_by_default.rb | 2 +- spec/models/customer_spec.rb | 8 +++----- spec/models/user_spec.rb | 8 +++----- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/spec/dummy/config/initializers/active_record_belongs_to_required_by_default.rb b/spec/dummy/config/initializers/active_record_belongs_to_required_by_default.rb index 78f4530..c913097 100644 --- a/spec/dummy/config/initializers/active_record_belongs_to_required_by_default.rb +++ b/spec/dummy/config/initializers/active_record_belongs_to_required_by_default.rb @@ -2,4 +2,4 @@ # Require `belongs_to` associations by default. This is a new Rails 5.0 default, # so introduced as a config to ensure apps made with earlier versions of Rails aren't affected when upgrading. -Rails.application.config.active_record.belongs_to_required_by_default = true +Rails.application.config.active_record.belongs_to_required_by_default = false diff --git a/spec/models/customer_spec.rb b/spec/models/customer_spec.rb index b6fc77e..1db9a4e 100644 --- a/spec/models/customer_spec.rb +++ b/spec/models/customer_spec.rb @@ -20,24 +20,22 @@ end describe '#split_full_name' do - let(:company) { Company.create(name: 'Joy Inc.') } - context 'with last_name' do - let(:subject) { Customer.create(full_name: 'Doe', company_id: company.id) } + let(:subject) { Customer.create(full_name: 'Doe') } it { expect(subject.first_name).to be_nil } it { expect(subject.last_name).to eq 'Doe' } end context 'with first_name and last_name' do - let(:subject) { Customer.create(full_name: 'John Doe', company_id: company.id) } + let(:subject) { Customer.create(full_name: 'John Doe') } it { expect(subject.first_name).to eq 'John' } it { expect(subject.last_name).to eq 'Doe' } end context 'with first_name, middle_name and last_name' do - let(:subject) { Customer.create(full_name: 'John F. Doe', company_id: company.id) } + let(:subject) { Customer.create(full_name: 'John F. Doe') } it { expect(subject.first_name).to eq 'John F.' } it { expect(subject.last_name).to eq 'Doe' } diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index a6140ff..69f63e6 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -21,13 +21,11 @@ end describe 'has secure password' do - let(:company) { Company.create(name: 'Joy Inc.') } - it { is_expected.to have_secure_password } it { is_expected.to validate_length_of(:password) } - it { expect(User.new(email: 'user@email.com', password: nil, company_id: company.id).save).to be_falsey } - it { expect(User.new(email: 'user@email.com', password: 'foo', company_id: company.id).save).to be_falsey } - it { expect(User.new(email: 'user@email.com', password: 'af3714ff0ffae', company_id: company.id).save).to be_truthy } + it { expect(User.new(email: 'user@email.com', password: nil).save).to be_falsey } + it { expect(User.new(email: 'user@email.com', password: 'foo').save).to be_falsey } + it { expect(User.new(email: 'user@email.com', password: 'af3714ff0ffae').save).to be_truthy } end end From fe7de35f67a6aecb569c2b3c73b3d633a22749b1 Mon Sep 17 00:00:00 2001 From: Luca Tironi Date: Sun, 14 Feb 2016 14:46:53 +0100 Subject: [PATCH 5/9] Update travis config --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0425142..02983ad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: ruby rvm: - - 2.2.3 -before_install: gem install bundler -v 1.10.6 + - 2.3.0 +before_install: gem install bundler -v 1.11.2 cache: - bundler addons: From d5f3e52684ef1ecfa0d247b62268192adb562d69 Mon Sep 17 00:00:00 2001 From: Luca Tironi Date: Sun, 14 Feb 2016 15:02:59 +0100 Subject: [PATCH 6/9] Remove deprecated code --- spec/dummy/config/application.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb index 463f9b9..67348e8 100644 --- a/spec/dummy/config/application.rb +++ b/spec/dummy/config/application.rb @@ -14,8 +14,5 @@ class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. - - # Do not swallow errors in after_commit/after_rollback callbacks. - config.active_record.raise_in_transactional_callbacks = true end end From b250c9218d4ee121ce42509e61809fa250b42285 Mon Sep 17 00:00:00 2001 From: Luca Tironi Date: Sun, 14 Feb 2016 15:10:09 +0100 Subject: [PATCH 7/9] Update schema.rb --- spec/dummy/db/schema.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/spec/dummy/db/schema.rb b/spec/dummy/db/schema.rb index 02d28a4..2ec18b9 100644 --- a/spec/dummy/db/schema.rb +++ b/spec/dummy/db/schema.rb @@ -21,10 +21,9 @@ t.string "user_agent" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.index ["user_id"], name: "index_authentication_tokens_on_user_id" end - add_index "authentication_tokens", ["user_id"], name: "index_authentication_tokens_on_user_id" - create_table "companies", force: :cascade do |t| t.string "name" t.datetime "created_at", null: false @@ -40,19 +39,17 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "company_id" + t.index ["company_id"], name: "index_customers_on_company_id" end - add_index "customers", ["company_id"], name: "index_customers_on_company_id" - create_table "users", force: :cascade do |t| t.string "email" t.string "password_digest" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "company_id" + t.index ["company_id"], name: "index_users_on_company_id" + t.index ["email"], name: "index_users_on_email" end - add_index "users", ["company_id"], name: "index_users_on_company_id" - add_index "users", ["email"], name: "index_users_on_email" - end From 81cecb0e2eba8906a4303a514a60f9ee9f1dca6c Mon Sep 17 00:00:00 2001 From: Luca Tironi Date: Sun, 14 Feb 2016 15:50:01 +0100 Subject: [PATCH 8/9] Downgrade to rails5 beta 1.1 to investigate sqlite3 bug on travis --- primegap-core.gemspec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/primegap-core.gemspec b/primegap-core.gemspec index 4d875da..0508ea3 100644 --- a/primegap-core.gemspec +++ b/primegap-core.gemspec @@ -17,9 +17,9 @@ Gem::Specification.new do |spec| spec.test_files = Dir['spec/**/*'] # Rails dependencies - spec.add_dependency 'railties', '>= 5.0.0.beta2' - spec.add_dependency 'activerecord', '>= 5.0.0.beta2' - spec.add_dependency 'actionmailer', '>= 5.0.0.beta2' + spec.add_dependency 'railties', '>= 5.0.0.beta1.1' + spec.add_dependency 'activerecord', '>= 5.0.0.beta1.1' + spec.add_dependency 'actionmailer', '>= 5.0.0.beta1.1' # Other dependecies spec.add_dependency 'bcrypt', '~> 3.1.7' From 302742efc2ca88db436a4524a04a990d56bc4533 Mon Sep 17 00:00:00 2001 From: Luca Tironi Date: Sun, 14 Feb 2016 15:53:42 +0100 Subject: [PATCH 9/9] Lock the rails 5 version to beta 1.1 --- primegap-core.gemspec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/primegap-core.gemspec b/primegap-core.gemspec index 0508ea3..75f2155 100644 --- a/primegap-core.gemspec +++ b/primegap-core.gemspec @@ -17,9 +17,9 @@ Gem::Specification.new do |spec| spec.test_files = Dir['spec/**/*'] # Rails dependencies - spec.add_dependency 'railties', '>= 5.0.0.beta1.1' - spec.add_dependency 'activerecord', '>= 5.0.0.beta1.1' - spec.add_dependency 'actionmailer', '>= 5.0.0.beta1.1' + spec.add_dependency 'railties', '5.0.0.beta1.1' + spec.add_dependency 'activerecord', '5.0.0.beta1.1' + spec.add_dependency 'actionmailer', '5.0.0.beta1.1' # Other dependecies spec.add_dependency 'bcrypt', '~> 3.1.7'