Skip to content

Commit

Permalink
Merge branch 'feature/rails-5-2' of github.com:refinery/refinerycms i…
Browse files Browse the repository at this point in the history
…nto feature/rails-5-2
  • Loading branch information
bricesanchez committed Jun 4, 2018
2 parents 046265e + 164c441 commit 830ba2f
Show file tree
Hide file tree
Showing 56 changed files with 559 additions and 410 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ end
if !ENV['TRAVIS'] || ENV['DB'] == 'mysql'
group :mysql do
gem 'activerecord-jdbcmysql-adapter', '>= 1.3.0.rc1', platform: :jruby
gem 'mysql2', '~> 0.3.18', :platform => :ruby
gem 'mysql2', '~> 0.4.10', :platform => :ruby
end
end

Expand Down
84 changes: 58 additions & 26 deletions changelog.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions core/lib/generators/refinery/engine/engine_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ def reject_file?(file)
def in_frontend_directory?(file)
file.to_s.include?('app') && file.to_s.scan(/admin|models|mailers/).empty?
end

end
end
2 changes: 1 addition & 1 deletion core/lib/generators/refinery/engine/templates/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ end

platforms :ruby do
gem 'sqlite3'
gem 'mysql2'
gem 'mysql2', '~> 0.4.10'
gem 'pg'
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module Refinery
end

def find_page
@page = ::Refinery::Page.where(:link_url => "/<%= plural_name %>").first
@page = ::Refinery::Page.where(link_url: "<%= index_route %>").first
end

end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Refinery
<% end %>
<% if localized? -%>

extend Mobility
translates <%= localized_attributes.map { |a| ":#{a.name}" }.join(', ') %>
<% end -%>
<% if string_attributes.any? -%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<% if localized? -%>
<%%= render '/refinery/admin/locale_picker',
:current_locale => Globalize.locale %>
:current_locale => Mobility.locale %>
<% end -%>
<% attributes.each_with_index do |attribute, index| -%>
<% if attribute.refinery_type == :image -%>
Expand Down Expand Up @@ -52,7 +52,7 @@
continue_editing: false,
delete_title: t('delete', scope: 'refinery.<%= plural_name %>.admin.<%= plural_name %>.<%= singular_name %>'),
delete_confirmation: t('message', scope: 'refinery.admin.delete'<% if (title = attributes.detect { |a| a.type.to_s == "string" }).present? %>, title: @<%= singular_name %>.<%= title.name %><% end %>),
cancel_url: refinery.<%= plural_name %>_admin_<%= plural_name %>_path -%>
cancel_url: refinery.<%= namespacing.underscore %>_admin_<%= plural_name %>_path -%>
<%% end -%>
<% if text_areas.any? -%>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,30 @@ class Create<%= namespacing %><%= class_name.pluralize %> < ActiveRecord::Migrat

def up
create_table :refinery_<%= "#{namespacing.underscore}_" if table_name != namespacing.underscore.pluralize -%><%= table_name %> do |t|
<% attributes.each do |attribute| -%>
<% (attributes - localized_attributes).each do |attribute| -%>
t.<%= attribute.type %> :<%= attribute.column_name %>
<% end -%>
t.integer :position

t.timestamps
end

<% if localized? %>
Refinery::<%= namespacing %>::<%= class_name %>.create_translation_table! <%= attributes_for_translation_table %>
create_table :<%= localized_table_name %> do |t|
<% localized_attributes.each do |attribute| -%>
t.<%= attribute.type %> :<%= attribute.column_name %>
<% end -%>
t.string :locale, null: false
t.integer :refinery_<%= singular_table_name %>_id, null: false
t.timestamps
end

add_index :<%= localized_table_name %>, :locale, name: :index_<%= localized_table_name %>_on_locale
add_index :<%= localized_table_name %>, [:refinery_<%= singular_table_name %>_id, :locale], name: :index_<%= Digest::SHA1.hexdigest(localized_table_name) %>, unique: true
<% end %>
end


def down
if defined?(::Refinery::UserPlugin)
::Refinery::UserPlugin.destroy_all({:name => "refinerycms-<%= namespacing.underscore %>"})
Expand All @@ -25,8 +37,7 @@ class Create<%= namespacing %><%= class_name.pluralize %> < ActiveRecord::Migrat
<% end %>
drop_table :refinery_<%= "#{namespacing.underscore}_" if table_name != namespacing.underscore.pluralize -%><%= table_name %>
<% if localized? %>
Refinery::<%= namespacing %>::<%= class_name %>.drop_translation_table!
drop_table :<%= localized_table_name %>
<% end %>
end

end
9 changes: 9 additions & 0 deletions core/lib/refinery/core/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ def refinery_inclusion!
WillPaginate.per_page = 20
end

initializer "refinery.mobility" do
Mobility.configure do |config|
config.default_backend = :table
config.accessor_method = :translates
config.query_method = :i18n
config.default_options[:dirty] = true
end
end

before_inclusion do
Refinery::Plugin.register do |plugin|
plugin.pathname = root
Expand Down
19 changes: 18 additions & 1 deletion core/lib/refinery/extension_generation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ def localized_attributes
@localized_attributes ||= attributes.select{ |a| options[:i18n].include?(a.name)}
end

def localized_table_name
localized_table_name = [ 'refinery']
localized_table_name << namespacing.underscore if table_name != namespacing.underscore.pluralize
localized_table_name << [ singular_table_name, 'translations']
localized_table_name.join('_')
end

def attributes_for_translation_table
localized_attributes.inject([]) { |memo, attr| memo << ":#{attr.name} => :#{attr.type}"}.join(', ')
end
Expand Down Expand Up @@ -333,6 +340,14 @@ def substitute_path_placeholders(path)
gsub('namespace', namespacing.underscore)
end

def index_route
if namespacing.underscore == plural_name
'/' + plural_name
else
'/' + namespacing.underscore + '/' + plural_name
end
end

def viable_templates
@viable_templates ||= begin
all_templates.reject(&method(:reject_template?)).inject({}) do |hash, path|
Expand Down Expand Up @@ -393,8 +408,10 @@ def templated_merge!
end
end

# merge_rb is only used for merging routes.rb
# Put destination lines first, so that extension namespaced routes precede the default extension route
def merge_rb
(source_lines[0..-2] + destination_lines[1..-2] + [source_lines.last]).join "\n"
(destination_lines[0..-2] + source_lines[1..-2] + [destination_lines.last]).join "\n"
end

def merge_yaml
Expand Down
2 changes: 1 addition & 1 deletion core/lib/refinery/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Refinery
class Version
@major = 4
@minor = 0
@tiny = 1
@tiny = 2
@build = nil

class << self
Expand Down
5 changes: 2 additions & 3 deletions core/refinerycms-core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require File.expand_path('../../core/lib/refinery/version', __FILE__)

version = Refinery::Version.to_s
rails_version = ['>= 5.2.0.rc2', '< 6']
rails_version = ['>= 5.2.0', '< 6']

Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
Expand All @@ -22,8 +22,7 @@ Gem::Specification.new do |s|

s.required_ruby_version = Refinery::Version.required_ruby_version

s.add_dependency 'refinerycms-i18n', ['~> 4.0', '>= 4.0.0']
s.add_dependency 'awesome_nested_set', ['~> 3.0', '>= 3.0.0']
s.add_dependency 'refinerycms-i18n', ['~> 5.0', '>= 5.0.0']
s.add_dependency 'railties', rails_version
s.add_dependency 'activerecord', rails_version
s.add_dependency 'actionpack', rails_version
Expand Down
5 changes: 2 additions & 3 deletions core/spec/features/refinery/application_layout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ module Refinery
end

describe 'body' do
it "id is the page's canonical id" do
it "has an id that includes the page's canonical name" do
visit home_page.url

expect(page).to have_css 'body#home-page'
expect(page.find("body")[:id]).to eq "home-page"
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions core/spec/helpers/refinery/translation_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ module Refinery
let(:page) { FactoryBot.build(:page) }

before do
Globalize.with_locale(:en) do
Mobility.with_locale(:en) do
page.title = "draft"
page.save!
end

Globalize.with_locale(:lv) do
Mobility.with_locale(:lv) do
page.title = "melnraksts"
page.save!
end
Expand All @@ -33,7 +33,7 @@ module Refinery

context "when title for current locale isn't available" do
it "returns existing title from translations" do
Page.translation_class.where(locale: :en).first.destroy
Page::Translation.where(locale: :en).first.destroy
expect(helper.translated_field(page, :title)).to eq("melnraksts")
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Refinery
describe EngineGenerator do
include GeneratorSpec::TestCase
destination File.expand_path("../../../../../../tmp", __FILE__)
let(:extension_root){"#{destination_root}/vendor/extensions/rspec_product_tests"}

before do
prepare_destination
Expand Down Expand Up @@ -41,6 +42,13 @@ module Refinery
end
}
end

it "does not namespace the link_url in the extension controller" do
File.read("#{extension_root}/app/controllers/refinery/rspec_product_tests/rspec_product_tests_controller.rb") do |file|
expect(file.grep(%r{/:link_url => "/rspec_product_tests"\)\.first/})).to be_truthy
end
end

end

context "when generating a resource inside existing extensions dir" do
Expand All @@ -66,16 +74,29 @@ module Refinery
end

it "appends existing seeds file" do
File.open("#{destination_root}/vendor/extensions/rspec_product_tests/db/seeds.rb") do |file|
File.open("#{extension_root}/db/seeds.rb") do |file|
expect(file.grep(%r{/rspec_product_tests|/rspec_item_tests}).count).to eq(2)
end
end

it "appends routes to the routes file" do
File.open("#{destination_root}/vendor/extensions/rspec_product_tests/config/routes.rb") do |file|
File.open("#{extension_root}/config/routes.rb") do |file|
expect(file.grep(%r{rspec_item_tests}).count).to eq(2)
end
end

it "places second and subsequent routes before the primary extension routes" do
content = File.read("#{extension_root}/config/routes.rb")
item_front_end_route = content.index("resources :rspec_item_tests, :only => [:index, :show]")
product_front_end_route = content.index("resources :rspec_product_tests, :path => '', :only => [:index, :show]")
expect(item_front_end_route).to be < product_front_end_route
end

it "uses the namespaced url in the extension controller" do
content = File.read("#{extension_root}/app/controllers/refinery/rspec_product_tests/rspec_item_tests_controller.rb") do |file|
expect(file.grep(%r{/:link_url => "/rspec_product_tests/rspec_item_tests"\)\.first/})).to be_truthy
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ module Refinery
let(:page) { FactoryBot.build(:page) }

before do
Globalize.with_locale(:en) do
Mobility.with_locale(:en) do
page.title = "draft"
page.save!
end

Globalize.with_locale(:lv) do
Mobility.with_locale(:lv) do
page.title = "melnraksts"
page.save!
end
Expand All @@ -25,7 +25,7 @@ module Refinery

context "when title for current locale isn't available" do
it "returns existing title from translations" do
Page.translation_class.where(locale: :en).first.destroy
Page::Translation.where(locale: :en).first.destroy
expect(TranslatedFieldPresenter.new(page).call(:title)).to eq("melnraksts")
end
end
Expand Down
Loading

0 comments on commit 830ba2f

Please sign in to comment.