From 3ebfa81ef85ed412e62a8acabe647fc5bd7731ad Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Fri, 20 Apr 2018 15:19:47 -0400 Subject: [PATCH 01/11] Add support for Mobility --- Gemfile | 7 +++++- app/models/refinery/image_page.rb | 3 +-- .../20101014230041_create_page_images.rb | 2 +- ...511215016_translate_page_image_captions.rb | 25 ++++++++----------- lib/refinery/page_images.rb | 3 +-- refinerycms-page-images.gemspec | 1 - 6 files changed, 19 insertions(+), 22 deletions(-) diff --git a/Gemfile b/Gemfile index f702095..a7a36c8 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,8 @@ source "http://rubygems.org" gemspec -git "https://github.com/refinery/refinerycms", branch: "master" do +# TODO: use master branch before merging this PR +git "https://github.com/refinery/refinerycms", branch: "feature/mobility" do gem 'refinerycms' group :development, :test do @@ -10,6 +11,10 @@ git "https://github.com/refinery/refinerycms", branch: "master" do end end +# TODO: remove refinerycms-i18n and mobility from this Gemfile before merging this PR +gem 'refinerycms-i18n', git: "https://github.com/refinery/refinerycms-i18n", branch: 'feature/mobility' +gem 'mobility', git: "https://github.com/shioyama/mobility", branch: 'master' + gem 'refinerycms-wymeditor', ['~> 2.0', '>= 2.0.0'] group :development do diff --git a/app/models/refinery/image_page.rb b/app/models/refinery/image_page.rb index c4b57b0..974bbca 100644 --- a/app/models/refinery/image_page.rb +++ b/app/models/refinery/image_page.rb @@ -4,8 +4,7 @@ class ImagePage < Refinery::Core::BaseModel belongs_to :image belongs_to :page, polymorphic: true, touch: true + extend Mobility translates :caption - - attribute :caption end end diff --git a/db/migrate/20101014230041_create_page_images.rb b/db/migrate/20101014230041_create_page_images.rb index a815424..7058bc1 100644 --- a/db/migrate/20101014230041_create_page_images.rb +++ b/db/migrate/20101014230041_create_page_images.rb @@ -1,6 +1,6 @@ class CreatePageImages < ActiveRecord::Migration[4.2] def change - create_table Refinery::ImagePage.table_name, :id => false do |t| + create_table Refinery::ImagePage.table_name do |t| t.integer :image_id t.integer :page_id t.integer :position diff --git a/db/migrate/20110511215016_translate_page_image_captions.rb b/db/migrate/20110511215016_translate_page_image_captions.rb index 9182945..0401cb9 100644 --- a/db/migrate/20110511215016_translate_page_image_captions.rb +++ b/db/migrate/20110511215016_translate_page_image_captions.rb @@ -1,22 +1,17 @@ class TranslatePageImageCaptions < ActiveRecord::Migration[4.2] - def up - add_column Refinery::ImagePage.table_name, :id, :primary_key + def change + create_table :refinery_image_page_translations do |t| - Refinery::ImagePage.reset_column_information - unless defined?(Refinery::ImagePage::Translation) && Refinery::ImagePage::Translation.table_exists? - Refinery::ImagePage.create_translation_table!({ - :caption => :text - }, { - :migrate_data => true - }) - end - end + # Translated attribute(s) + t.text :caption - def down - Refinery::ImagePage.reset_column_information + t.string :locale, null: false + t.integer :refinery_image_page_id, null: false - Refinery::ImagePage.drop_translation_table! :migrate_data => true + t.timestamps null: false + end - remove_column Refinery::ImagePage.table_name, :id + add_index :refinery_image_page_translations, :locale, name: :index_refinery_image_page_translations_on_locale + add_index :refinery_image_page_translations, [:refinery_image_page_id, :locale], name: :index_114aab0bbdedc79d0ec4f4b, unique: true end end diff --git a/lib/refinery/page_images.rb b/lib/refinery/page_images.rb index 288c396..e7fb6fa 100644 --- a/lib/refinery/page_images.rb +++ b/lib/refinery/page_images.rb @@ -1,5 +1,4 @@ -require 'refinerycms-core' -require 'globalize' +require 'refinerycms-pages' module Refinery autoload :PageImagesGenerator, 'generators/refinery/page_images_generator' diff --git a/refinerycms-page-images.gemspec b/refinerycms-page-images.gemspec index ec108e7..cceb53c 100644 --- a/refinerycms-page-images.gemspec +++ b/refinerycms-page-images.gemspec @@ -14,7 +14,6 @@ Gem::Specification.new do |s| s.add_dependency 'refinerycms-pages', ['~> 4.0', '>= 4.0.0'] s.add_dependency 'decorators', '~> 2.0' - s.add_dependency 'globalize', '~> 5.1.0' s.cert_chain = [File.expand_path("../certs/parndt.pem", __FILE__)] if $0 =~ /gem\z/ && ARGV.include?("build") && ARGV.include?(__FILE__) From 40cccd545b126d2d42e059565c21fe05193d7221 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Fri, 27 Apr 2018 21:02:45 -0400 Subject: [PATCH 02/11] Update ruby versions in travis config --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index a865c3c..7657083 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,7 @@ env: - DB=postgresql - DB=mysql rvm: - - 2.4.2 - - 2.3.5 - - 2.2.8 \ No newline at end of file + - 2.5.1 + - 2.4.4 + - 2.3.7 + - 2.2.10 \ No newline at end of file From 38c7ea6bfb58744ac7f2d2fa2037319984d4de7b Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Fri, 27 Apr 2018 21:03:10 -0400 Subject: [PATCH 03/11] Remove mobility gem source --- Gemfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Gemfile b/Gemfile index a7a36c8..f11e26a 100644 --- a/Gemfile +++ b/Gemfile @@ -13,7 +13,6 @@ end # TODO: remove refinerycms-i18n and mobility from this Gemfile before merging this PR gem 'refinerycms-i18n', git: "https://github.com/refinery/refinerycms-i18n", branch: 'feature/mobility' -gem 'mobility', git: "https://github.com/shioyama/mobility", branch: 'master' gem 'refinerycms-wymeditor', ['~> 2.0', '>= 2.0.0'] From add4cd0f4f163bba9b21ef97a90a4fed659dd2a4 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Thu, 3 May 2018 13:17:15 -0400 Subject: [PATCH 04/11] Update dependency to refinerycms-core Because page images could be added to other extensions than pages --- lib/refinery/page_images.rb | 2 +- refinerycms-page-images.gemspec | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/refinery/page_images.rb b/lib/refinery/page_images.rb index e7fb6fa..848e988 100644 --- a/lib/refinery/page_images.rb +++ b/lib/refinery/page_images.rb @@ -1,4 +1,4 @@ -require 'refinerycms-pages' +require 'refinerycms-core' module Refinery autoload :PageImagesGenerator, 'generators/refinery/page_images_generator' diff --git a/refinerycms-page-images.gemspec b/refinerycms-page-images.gemspec index cceb53c..8ef8afb 100644 --- a/refinerycms-page-images.gemspec +++ b/refinerycms-page-images.gemspec @@ -12,8 +12,7 @@ Gem::Specification.new do |s| s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- spec/*`.split("\n") - s.add_dependency 'refinerycms-pages', ['~> 4.0', '>= 4.0.0'] - s.add_dependency 'decorators', '~> 2.0' + s.add_dependency 'refinerycms-core', ['~> 4.0', '>= 4.0.0'] s.cert_chain = [File.expand_path("../certs/parndt.pem", __FILE__)] if $0 =~ /gem\z/ && ARGV.include?("build") && ARGV.include?(__FILE__) From 76e49d1aaa0bae57c6caee72d8bd1cc5c9a76c79 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Thu, 3 May 2018 13:17:36 -0400 Subject: [PATCH 05/11] Add optional: true to belongs_to relation with :page --- app/models/refinery/image_page.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/refinery/image_page.rb b/app/models/refinery/image_page.rb index 974bbca..92e4033 100644 --- a/app/models/refinery/image_page.rb +++ b/app/models/refinery/image_page.rb @@ -2,9 +2,9 @@ module Refinery class ImagePage < Refinery::Core::BaseModel belongs_to :image - belongs_to :page, polymorphic: true, touch: true + belongs_to :page, polymorphic: true, touch: true, optional: true extend Mobility translates :caption end -end +end \ No newline at end of file From 7a9d50bab131b112e8bd57c98715ee09c50c3974 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Fri, 4 May 2018 21:41:13 -0400 Subject: [PATCH 06/11] Downgrade ruby versions in travis config This will temp. fix bundler issue in Travis --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7657083..9930a54 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ env: - DB=postgresql - DB=mysql rvm: - - 2.5.1 - - 2.4.4 - - 2.3.7 - - 2.2.10 \ No newline at end of file + - 2.5.0 + - 2.4.3 + - 2.3.6 + - 2.2.9 \ No newline at end of file From 508f7a6a0746ca2d348877a5c0e323239ee5ef54 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 9 May 2018 09:43:03 -0400 Subject: [PATCH 07/11] Add dependency to refinerycms-images --- refinerycms-page-images.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/refinerycms-page-images.gemspec b/refinerycms-page-images.gemspec index 8ef8afb..64c0e33 100644 --- a/refinerycms-page-images.gemspec +++ b/refinerycms-page-images.gemspec @@ -13,6 +13,7 @@ Gem::Specification.new do |s| s.test_files = `git ls-files -- spec/*`.split("\n") s.add_dependency 'refinerycms-core', ['~> 4.0', '>= 4.0.0'] + s.add_dependency 'refinerycms-images', ['~> 4.0', '>= 4.0.0'] s.cert_chain = [File.expand_path("../certs/parndt.pem", __FILE__)] if $0 =~ /gem\z/ && ARGV.include?("build") && ARGV.include?(__FILE__) From 663bd191e70a22e81722a96ec610208b539951a0 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 9 May 2018 09:43:37 -0400 Subject: [PATCH 08/11] Apply Refinery::Page decorators only if defined --- .../refinery/admin/pages_controller_decorator.rb | 16 +++++++++------- .../refinery/page_images_page_decorator.rb | 6 +++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/decorators/controllers/refinery/admin/pages_controller_decorator.rb b/app/decorators/controllers/refinery/admin/pages_controller_decorator.rb index be718ed..32e83a8 100644 --- a/app/decorators/controllers/refinery/admin/pages_controller_decorator.rb +++ b/app/decorators/controllers/refinery/admin/pages_controller_decorator.rb @@ -1,8 +1,10 @@ -Refinery::Admin::PagesController.prepend( - Module.new do - def permitted_page_params - params[:page][:images_attributes]={} if params[:page][:images_attributes].nil? - super << [images_attributes: [:id, :caption, :image_page_id]] +if defined?(Refinery::Page) + Refinery::Admin::PagesController.prepend( + Module.new do + def permitted_page_params + params[:page][:images_attributes]={} if params[:page][:images_attributes].nil? + super << [images_attributes: [:id, :caption, :image_page_id]] + end end - end -) \ No newline at end of file + ) +end \ No newline at end of file diff --git a/app/decorators/models/refinery/page_images_page_decorator.rb b/app/decorators/models/refinery/page_images_page_decorator.rb index d8d21f6..c45ab1f 100644 --- a/app/decorators/models/refinery/page_images_page_decorator.rb +++ b/app/decorators/models/refinery/page_images_page_decorator.rb @@ -1,3 +1,3 @@ -Refinery::Page.include RefineryPageImages::AddImagesWithCaptionsConcern - - +if defined?(Refinery::Page) + Refinery::Page.include RefineryPageImages::AddImagesWithCaptionsConcern +end \ No newline at end of file From 1fe58666126dfca19af85d9484f57f58686570d3 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 22 Aug 2018 09:23:16 -0400 Subject: [PATCH 09/11] Gemfile: switch back to master branch of refinerycms --- Gemfile | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index f11e26a..f702095 100644 --- a/Gemfile +++ b/Gemfile @@ -2,8 +2,7 @@ source "http://rubygems.org" gemspec -# TODO: use master branch before merging this PR -git "https://github.com/refinery/refinerycms", branch: "feature/mobility" do +git "https://github.com/refinery/refinerycms", branch: "master" do gem 'refinerycms' group :development, :test do @@ -11,9 +10,6 @@ git "https://github.com/refinery/refinerycms", branch: "feature/mobility" do end end -# TODO: remove refinerycms-i18n and mobility from this Gemfile before merging this PR -gem 'refinerycms-i18n', git: "https://github.com/refinery/refinerycms-i18n", branch: 'feature/mobility' - gem 'refinerycms-wymeditor', ['~> 2.0', '>= 2.0.0'] group :development do From 6032bd2b143a2c97d8b916e9f1b6c87dfddc6fd1 Mon Sep 17 00:00:00 2001 From: Brice Sanchez Date: Wed, 29 Aug 2018 08:13:57 -0400 Subject: [PATCH 10/11] Now use Module#prepend for decorators --- .../admin/blogposts_controller_decorator.rb | 18 +++++++------- .../admin/pages_controller_decorator.rb | 18 +++++++------- .../refinery/page_images_page_decorator.rb | 23 +++++++++++++++--- .../add_images_with_captions_concern.rb | 24 ------------------- 4 files changed, 36 insertions(+), 47 deletions(-) delete mode 100644 app/models/concerns/refinery_page_images/add_images_with_captions_concern.rb diff --git a/app/decorators/controllers/refinery/admin/blogposts_controller_decorator.rb b/app/decorators/controllers/refinery/admin/blogposts_controller_decorator.rb index 65ab8a2..e6b0a4b 100644 --- a/app/decorators/controllers/refinery/admin/blogposts_controller_decorator.rb +++ b/app/decorators/controllers/refinery/admin/blogposts_controller_decorator.rb @@ -1,10 +1,8 @@ -if defined?(Refinery::Blog) - Refinery::Blog::Admin::PostsController.prepend( - Module.new do - def permitted_post_params - params[:post][:images_attributes]={} if params[:post][:images_attributes].nil? - super << [images_attributes: [:id, :caption, :image_page_id]] - end - end - ) -end \ No newline at end of file +module RefineryPageImagesAddRefineryBlogAdminPostsCrontrollerParams + def permitted_post_params + params[:post][:images_attributes]={} if params[:post][:images_attributes].nil? + super << [images_attributes: [:id, :caption, :image_page_id]] + end +end + +Refinery::Blog::Admin::PostsController.prepend(RefineryPageImagesAddRefineryBlogAdminPostsCrontrollerParams) rescue NameError \ No newline at end of file diff --git a/app/decorators/controllers/refinery/admin/pages_controller_decorator.rb b/app/decorators/controllers/refinery/admin/pages_controller_decorator.rb index 32e83a8..576b503 100644 --- a/app/decorators/controllers/refinery/admin/pages_controller_decorator.rb +++ b/app/decorators/controllers/refinery/admin/pages_controller_decorator.rb @@ -1,10 +1,8 @@ -if defined?(Refinery::Page) - Refinery::Admin::PagesController.prepend( - Module.new do - def permitted_page_params - params[:page][:images_attributes]={} if params[:page][:images_attributes].nil? - super << [images_attributes: [:id, :caption, :image_page_id]] - end - end - ) -end \ No newline at end of file +module RefineryPageImagesAddRefineryAdminPagesControllerParams + def permitted_page_params + params[:page][:images_attributes]={} if params[:page][:images_attributes].nil? + super << [images_attributes: [:id, :caption, :image_page_id]] + end +end + +Refinery::Admin::PagesController.prepend(RefineryPageImagesAddRefineryAdminPagesControllerParams) rescue NameError \ No newline at end of file diff --git a/app/decorators/models/refinery/page_images_page_decorator.rb b/app/decorators/models/refinery/page_images_page_decorator.rb index c45ab1f..bcfea9a 100644 --- a/app/decorators/models/refinery/page_images_page_decorator.rb +++ b/app/decorators/models/refinery/page_images_page_decorator.rb @@ -1,3 +1,20 @@ -if defined?(Refinery::Page) - Refinery::Page.include RefineryPageImages::AddImagesWithCaptionsConcern -end \ No newline at end of file +require 'ostruct' + +module RefineryPageImagesAddImagesWithCaptions + def self.prepended(base) + base.attr_accessor :images_with_captions + end + + def images_with_captions + @images_with_captions = image_pages.map do |ref| + OpenStruct.new( + { + image: Refinery::Image.find(ref.image_id), + caption: ref.caption || '' + } + ) + end + end +end + +Refinery::Page.prepend(RefineryPageImagesAddImagesWithCaptions) rescue NameError \ No newline at end of file diff --git a/app/models/concerns/refinery_page_images/add_images_with_captions_concern.rb b/app/models/concerns/refinery_page_images/add_images_with_captions_concern.rb deleted file mode 100644 index 9c1cd2c..0000000 --- a/app/models/concerns/refinery_page_images/add_images_with_captions_concern.rb +++ /dev/null @@ -1,24 +0,0 @@ -require 'ostruct' - -module RefineryPageImages - module AddImagesWithCaptionsConcern - extend ActiveSupport::Concern - included do - attr_accessor :images_with_captions - prepend(InstanceMethods) - end - - module InstanceMethods - def images_with_captions - @images_with_captions = image_pages.map do |ref| - OpenStruct.new( - { - image: Refinery::Image.find(ref.image_id), - caption: ref.caption || '' - } - ) - end - end - end - end -end \ No newline at end of file From 77a923b54411fd4ddb2916411d76bd4215ad069f Mon Sep 17 00:00:00 2001 From: Anita Graham Date: Mon, 13 Apr 2020 19:47:05 +0800 Subject: [PATCH 11/11] Change capybara locator to find, match: :first, so it will handle multiple entries on a page --- spec/features/attach_page_images_spec.rb | 3 +-- spec/spec_helper.rb | 1 + spec/support/refinery_login.rb | 0 3 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 spec/support/refinery_login.rb diff --git a/spec/features/attach_page_images_spec.rb b/spec/features/attach_page_images_spec.rb index d35a7a4..96dd3f9 100644 --- a/spec/features/attach_page_images_spec.rb +++ b/spec/features/attach_page_images_spec.rb @@ -6,7 +6,7 @@ # No-op block : use default configuration by default let(:configure) {} let(:create_page) { FactoryBot.create(:page_with_page_part) } - let(:navigate_to_edit) { click_link "Edit this page" } + let(:navigate_to_edit) { page.find('.edit_icon', match: :first).click } let(:page_images_tab_id) { "#custom_#{::I18n.t(:'refinery.plugins.refinery_page_images.tab_name')}_tab" } let(:setup_and_visit) do @@ -41,7 +41,6 @@ end let(:create_page) { FactoryBot.create(:page_with_image) } - let(:navigate_to_edit) { page.find('a[tooltip="Edit this page"]').click } it "shows a plain textarea when editing caption", js: true do setup_and_visit diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index bddb8bc..b688920 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,6 +7,7 @@ require 'rspec/rails' require 'capybara/rspec' +require 'capybara-screenshot/rspec' Rails.backtrace_cleaner.remove_silencers! diff --git a/spec/support/refinery_login.rb b/spec/support/refinery_login.rb new file mode 100644 index 0000000..e69de29