diff --git a/.travis.yml b/.travis.yml index a865c3c..9930a54 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.0 + - 2.4.3 + - 2.3.6 + - 2.2.9 \ No newline at end of file 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 be718ed..576b503 100644 --- a/app/decorators/controllers/refinery/admin/pages_controller_decorator.rb +++ b/app/decorators/controllers/refinery/admin/pages_controller_decorator.rb @@ -1,8 +1,8 @@ -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 +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 -) \ No newline at end of file +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 d8d21f6..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 @@ -Refinery::Page.include RefineryPageImages::AddImagesWithCaptionsConcern +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 diff --git a/app/models/refinery/image_page.rb b/app/models/refinery/image_page.rb index c4b57b0..92e4033 100644 --- a/app/models/refinery/image_page.rb +++ b/app/models/refinery/image_page.rb @@ -2,10 +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 - - attribute :caption end -end +end \ No newline at end of file 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..848e988 100644 --- a/lib/refinery/page_images.rb +++ b/lib/refinery/page_images.rb @@ -1,5 +1,4 @@ require 'refinerycms-core' -require 'globalize' module Refinery autoload :PageImagesGenerator, 'generators/refinery/page_images_generator' diff --git a/refinerycms-page-images.gemspec b/refinerycms-page-images.gemspec index ec108e7..64c0e33 100644 --- a/refinerycms-page-images.gemspec +++ b/refinerycms-page-images.gemspec @@ -12,9 +12,8 @@ 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 'globalize', '~> 5.1.0' + 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__) 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