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

Add Rails 6.1.0.alpha/master support #3515

Merged
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
9 changes: 7 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ source 'https://rubygems.org'
group :backend, :frontend, :core, :api do
gemspec require: false

rails_version = ENV['RAILS_VERSION'] || '~> 6.0.0'
gem 'rails', rails_version, require: false
# rubocop:disable Bundler/DuplicatedGem
if ENV['RAILS_VERSION'] == 'master'
gem 'rails', github: 'rails', require: false
else
gem 'rails', ENV['RAILS_VERSION'] || '~> 6.0.0', require: false
filippoliverani marked this conversation as resolved.
Show resolved Hide resolved
end
# rubocop:enable Bundler/DuplicatedGem

# Temporarily locking sprockets to v3.x
# see https://github.com/solidusio/solidus/issues/3374
Expand Down
1 change: 1 addition & 0 deletions api/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
Rails.cache.clear
end

config.include ActiveSupport::Testing::Assertions
config.include ActiveJob::TestHelper

config.use_transactional_fixtures = true
Expand Down
1 change: 1 addition & 0 deletions backend/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
end

config.include FactoryBot::Syntax::Methods
config.include ActiveSupport::Testing::Assertions
config.include ActiveJob::TestHelper

config.include Spree::TestingSupport::Preferences
Expand Down
26 changes: 26 additions & 0 deletions core/lib/spree/awesome_nested_set_override.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

module AwesomeNestedSetOvveride
filippoliverani marked this conversation as resolved.
Show resolved Hide resolved
# Add :polimorphic key option only when used to make it work with Rails 6.1+
# https://github.com/osmaelo/rails/commit/2c008d9f6311d92b3660193285230505e74a114f
# This can be removed when upgrading to an awesome_nested_set version
# compliant with Rails 6.1+.
def acts_as_nested_set_relate_parent!
# Disable Rubocop to keep original code for diffs
# rubocop:disable
options = {
:class_name => self.base_class.to_s,
filippoliverani marked this conversation as resolved.
Show resolved Hide resolved
:foreign_key => parent_column_name,
filippoliverani marked this conversation as resolved.
Show resolved Hide resolved
:primary_key => primary_column_name,
filippoliverani marked this conversation as resolved.
Show resolved Hide resolved
:counter_cache => acts_as_nested_set_options[:counter_cache],
filippoliverani marked this conversation as resolved.
Show resolved Hide resolved
:inverse_of => (:children unless acts_as_nested_set_options[:polymorphic]),
filippoliverani marked this conversation as resolved.
Show resolved Hide resolved
:touch => acts_as_nested_set_options[:touch]
filippoliverani marked this conversation as resolved.
Show resolved Hide resolved
}
options[:polymorphic] = true if acts_as_nested_set_options[:polymorphic]
options[:optional] = true if ActiveRecord::VERSION::MAJOR >= 5
belongs_to :parent, options
# rubocop:disable
end

CollectiveIdea::Acts::NestedSet.prepend self
filippoliverani marked this conversation as resolved.
Show resolved Hide resolved
end
4 changes: 4 additions & 0 deletions core/lib/spree/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,7 @@ class GatewayError < RuntimeError; end
require 'spree/preferences/store'
require 'spree/preferences/static_model_preferences'
require 'spree/preferences/scoped_store'

if Gem::Version.new(Rails.version) >= Gem::Version.new('6.1.0.alpha')
require 'spree/awesome_nested_set_override'
end
5 changes: 4 additions & 1 deletion core/lib/spree/testing_support/factories/user_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
end

factory :admin_user do
spree_roles { [Spree::Role.find_by(name: 'admin') || create(:role, name: 'admin')] }
after(:create) do |user, _|
admin_role = Spree::Role.find_by(name: 'admin') || create(:role, name: 'admin')
user.spree_roles << admin_role
end
end

factory :user_with_addresses do |_u|
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/ability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def initialize(_user)
let(:resource) { Object.new }

context 'with admin user' do
let(:user) { build :admin_user }
let(:user) { create :admin_user }
it_should_behave_like 'access granted'
it_should_behave_like 'index allowed'
end
Expand Down
1 change: 1 addition & 0 deletions core/spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
Rails.cache.clear
end

config.include ActiveSupport::Testing::Assertions
config.include ActiveJob::TestHelper
config.include FactoryBot::Syntax::Methods
end