diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b778325b94..0ba43ef1b9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,7 +12,7 @@ jobs: matrix: database: [ mysql, postgresql ] extension: [ core, dragonfly, images, pages, resources ] - ruby: [ 2.7, 2.6 ] + ruby: [ 3.1] fail-fast: false max-parallel: 20 runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index d9073f40c3..b35ceabdd9 100644 --- a/.gitignore +++ b/.gitignore @@ -97,3 +97,4 @@ Gemfile.lock # rspec failures .rspec_failures +Refinery Review.md diff --git a/Gemfile b/Gemfile index 17e0baf8dd..164020956a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,20 +1,26 @@ source 'https://rubygems.org' +ruby "3.1.2" gemspec +gem 'rails', "~>6.1" +gem 'net-smtp', require: false +gem 'net-imap', require: false +gem 'net-pop', require: false + + path "./" do gem "refinerycms-core" + gem "refinerycms-dragonfly" gem "refinerycms-images" gem "refinerycms-pages" gem "refinerycms-resources" end -gem 'refinerycms-i18n', github: 'refinery/refinerycms-i18n', branch: 'master' +gem 'refinerycms-i18n', git: 'https://github.com/refinery/refinerycms-i18n', branch: 'ruby3' # Add support for refinerycms-acts-as-indexed -gem 'refinerycms-acts-as-indexed', ['~> 4.0', '>= 4.0.0'], - git: 'https://github.com/refinery/refinerycms-acts-as-indexed', - branch: 'master' +gem 'refinerycms-acts-as-indexed', ['~> 4.0', '>= 4.0.0'], git: 'https://github.com/refinery/refinerycms-acts-as-indexed', branch: 'master' # Add the default visual editor, for now. gem 'refinerycms-wymeditor', ['~> 3.0', '>= 3.0.0'] @@ -43,6 +49,7 @@ group :development, :test do gem 'activejob' gem 'bootsnap', require: false gem 'listen', '~> 3.0' + gem 'rspec-rails', '~> 6.0.0.rc1' end group :test do @@ -53,9 +60,6 @@ group :test do gem 'rspec-retry' gem 'falcon' gem 'falcon-capybara' - - # TODO: Use beta source for Rails 6 support - gem 'rspec-rails', '~> 4.0.0.beta3' end # Load local gems according to Refinery developer preference. diff --git a/core/app/helpers/refinery/site_bar_helper.rb b/core/app/helpers/refinery/site_bar_helper.rb index 6d6519957e..96d0339077 100644 --- a/core/app/helpers/refinery/site_bar_helper.rb +++ b/core/app/helpers/refinery/site_bar_helper.rb @@ -3,24 +3,24 @@ module SiteBarHelper # Generates the link to determine where the site bar switch button returns to. def site_bar_switch_link - link_to_if(admin?, t('.switch_to_your_website', site_bar_translate_locale_args), + link_to_if(admin?, t('.switch_to_your_website', **site_bar_translate_locale_args), refinery.root_path(site_bar_translate_locale_args), 'data-turbolinks' => false) do - link_to t('.switch_to_your_website_editor', site_bar_translate_locale_args), + link_to t('.switch_to_your_website_editor', **site_bar_translate_locale_args), Refinery::Core.backend_path, 'data-turbolinks' => false end end def site_bar_edit_link return nil if admin? || @page.nil? - link_to t('refinery.admin.pages.edit', site_bar_translate_locale_args), + link_to t('refinery.admin.pages.edit', **site_bar_translate_locale_args), refinery.admin_edit_page_path(@page.nested_url, :switch_locale => (@page.translations.first.locale unless @page.translated_to_default_locale?)), 'data-turbolinks' => false end def site_bar_translate_locale_args - { :locale => Refinery::I18n.current_locale } + { locale: Refinery::I18n.current_locale } end def display_site_bar? diff --git a/core/app/helpers/refinery/translation_helper.rb b/core/app/helpers/refinery/translation_helper.rb index f3d36f3cbb..d211543bb7 100644 --- a/core/app/helpers/refinery/translation_helper.rb +++ b/core/app/helpers/refinery/translation_helper.rb @@ -3,7 +3,7 @@ module TranslationHelper # Overrides Rails' core I18n.t() function to produce a more helpful error message. # The default one wreaks havoc with CSS and makes it hard to understand the problem. - def t(key, options = {}) + def t(key, **options) if (val = super) =~ /class.+?translation_missing/ val = val.to_s.gsub(/]*>/, 'i18n: ').gsub('', '').gsub(', ', '.') end diff --git a/core/app/views/refinery/_site_bar.html.erb b/core/app/views/refinery/_site_bar.html.erb index e5fcb7993a..db909de859 100644 --- a/core/app/views/refinery/_site_bar.html.erb +++ b/core/app/views/refinery/_site_bar.html.erb @@ -17,12 +17,13 @@
- <%= Refinery::Core.site_name %> + <% Rails.logger.debug Refinery::Core.site_name %> + <%#= Refinery::Core.site_name %> - <%= link_to t('.log_out', site_bar_translate_locale_args), + <%= link_to t('.log_out', **site_bar_translate_locale_args), ::Refinery::Core.refinery_logout_path, - :id => 'logout' if ::Refinery::Core.refinery_logout_path.present? %> + id: 'logout' if ::Refinery::Core.refinery_logout_path.present? %>
diff --git a/core/app/views/refinery/admin/_error_messages.html.erb b/core/app/views/refinery/admin/_error_messages.html.erb index febb6a6dab..41274deb26 100644 --- a/core/app/views/refinery/admin/_error_messages.html.erb +++ b/core/app/views/refinery/admin/_error_messages.html.erb @@ -3,12 +3,12 @@

<%= t('.problems_in_following_fields') %>:

diff --git a/core/lib/refinery/core/engine.rb b/core/lib/refinery/core/engine.rb index ae0b04c84b..efe00dce90 100644 --- a/core/lib/refinery/core/engine.rb +++ b/core/lib/refinery/core/engine.rb @@ -45,11 +45,22 @@ def refinery_inclusion! 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 + Mobility.configure do + plugins do + backend :table + reader # Explicitly declare readers, + writer # writers, and + backend_reader # backend reader (post.title_backend, etc). + active_record # You must now also explicitly ask for ActiveRecord (or Sequel) + query # i18n is the default scope + cache # previously implicit + fallbacks + presence # previously implicit + default + attribute_methods # uncomment this to get methods like `translated_attributes` + dirty + end + # accessor_method not available in v1.0 end end diff --git a/core/lib/refinery/version.rb b/core/lib/refinery/version.rb index 3a6f11e49f..990c0c0e0c 100644 --- a/core/lib/refinery/version.rb +++ b/core/lib/refinery/version.rb @@ -13,7 +13,7 @@ def to_s end def required_ruby_version - '>= 2.5.5' + '>= 3.1' end end end diff --git a/core/spec/helpers/refinery/translation_helper_spec.rb b/core/spec/helpers/refinery/translation_helper_spec.rb index 10bbde9634..5339d9be45 100644 --- a/core/spec/helpers/refinery/translation_helper_spec.rb +++ b/core/spec/helpers/refinery/translation_helper_spec.rb @@ -15,8 +15,9 @@ module Refinery before do Mobility.with_locale(:en) do - page.title = "draft" - page.save! + # page.title = "draft" + # page.save! + page.update!({title: 'draft'}) end Mobility.with_locale(:lv) do diff --git a/core/spec/presenters/refinery/translated_field_presenter_spec.rb b/core/spec/presenters/refinery/translated_field_presenter_spec.rb index bad639bee2..6c9d51b18b 100644 --- a/core/spec/presenters/refinery/translated_field_presenter_spec.rb +++ b/core/spec/presenters/refinery/translated_field_presenter_spec.rb @@ -6,13 +6,11 @@ module Refinery before do Mobility.with_locale(:en) do - page.title = "draft" - page.save! + page.update!( title: "draft") end Mobility.with_locale(:lv) do - page.title = "melnraksts" - page.save! + page.update!(title: "melnraksts") end end diff --git a/core/spec/system/refinery/admin/xhr_paging_spec.rb b/core/spec/system/refinery/admin/xhr_paging_spec.rb index c1272f48f1..a60996c329 100644 --- a/core/spec/system/refinery/admin/xhr_paging_spec.rb +++ b/core/spec/system/refinery/admin/xhr_paging_spec.rb @@ -8,8 +8,8 @@ module Refinery # Refinery::Admin::ImagesController specifies :order => 'created_at DESC' in crudify let(:first_image) { Image.order('created_at DESC').first } let(:last_image) { Image.order('created_at DESC').last } - let!(:image_1) { FactoryBot.create :image } - let!(:image_2) { FactoryBot.create :image } + let!(:image_1) { FactoryBot.create(:image) } + let!(:image_2) { FactoryBot.create(:image) } before do allow(Image).to receive(:per_page).and_return(1) diff --git a/core/spec/system/refinery/site_bar_spec.rb b/core/spec/system/refinery/site_bar_spec.rb index 7c5add0ecc..0d05f6ec00 100644 --- a/core/spec/system/refinery/site_bar_spec.rb +++ b/core/spec/system/refinery/site_bar_spec.rb @@ -10,10 +10,10 @@ module Refinery context "when set" do before do allow(Refinery::Core).to receive(:refinery_logout_path).and_return(logout_path) - visit Refinery::Core.backend_path end it "is present" do + visit Refinery::Core.backend_path expect(page).to have_selector("a[href='#{logout_path}']") expect(page).to have_content("Log out") end diff --git a/images/lib/refinery/images/validators/image_size_validator.rb b/images/lib/refinery/images/validators/image_size_validator.rb index ecfdd589cc..e6aaecee7b 100644 --- a/images/lib/refinery/images/validators/image_size_validator.rb +++ b/images/lib/refinery/images/validators/image_size_validator.rb @@ -2,17 +2,16 @@ module Refinery module Images module Validators class ImageSizeValidator < ActiveModel::Validator - def validate(record) - image = record.image - - if image.respond_to?(:length) && image.length > Images.max_image_size - record.errors[:image] << ::I18n.t('too_big', - :scope => 'activerecord.errors.models.refinery/image', - :size => Images.max_image_size) - end + record.errors.add(:image, ::I18n.t('too_big', + scope: 'activerecord.errors.models.refinery/image', + size: Images.max_image_size)) if too_big(record.image) end + private + def too_big(image) + image.respond_to?(:length) && image.length > Images.max_image_size + end end end end diff --git a/images/lib/refinery/images/validators/image_update_validator.rb b/images/lib/refinery/images/validators/image_update_validator.rb index 0ab9fbb724..a2769bf2fd 100644 --- a/images/lib/refinery/images/validators/image_update_validator.rb +++ b/images/lib/refinery/images/validators/image_update_validator.rb @@ -7,7 +7,7 @@ def validate(record) if record.image_name_changed? record.errors.add :image_name, ::I18n.t("different_file_name", - :scope => "activerecord.errors.models.refinery/image") + scope: "activerecord.errors.models.refinery/image") end end diff --git a/images/spec/support/shared_examples/image_deleter.rb b/images/spec/support/shared_examples/image_deleter.rb index a8ff8cf90b..6c04e4f8de 100644 --- a/images/spec/support/shared_examples/image_deleter.rb +++ b/images/spec/support/shared_examples/image_deleter.rb @@ -1,27 +1,26 @@ -shared_examples_for 'deletes an image' do +shared_examples_for 'Delete' do before do raise "please set let(:initial_path)" if initial_path.blank? ensure_on(initial_path) end - let(:image_count) {[Refinery::Image.count, Refinery::Images.pages_per_admin_index].min} - let(:deleting_an_image) { - -> { - first("#records li").click_link(::I18n.t('delete', scope: 'refinery.admin.images')) - } - } + def deleting_an_image + first("#records li").click_link(::I18n.t('delete', scope: 'refinery.admin.images')) + end + + let(:image_count) { [Refinery::Image.count, Refinery::Images.pages_per_admin_index].min } it 'has a delete image link for each image' do expect(page).to have_selector('#records.images li a.confirm-delete', count: image_count) end it "removes an image" do - expect(deleting_an_image).to change(Refinery::Image, :count).by(-1) + expect { deleting_an_image }.to change(Refinery::Image, :count).by(-1) end it 'says the image has been removed' do image_title = page.has_selector?('#image_grid') ? find("#image_grid li:first").first("img")[:title] : - find("#image_list li:first").first("span.title").text + find("#image_list li:first").first("span.title").text expect(image_title).to be_present diff --git a/images/spec/support/shared_examples/image_editor.rb b/images/spec/support/shared_examples/image_editor.rb index 9a643a06cd..6e272ccd4b 100644 --- a/images/spec/support/shared_examples/image_editor.rb +++ b/images/spec/support/shared_examples/image_editor.rb @@ -1,3 +1,3 @@ -shared_examples 'edits an image' do +shared_examples 'Edit' do pending -end \ No newline at end of file +end diff --git a/images/spec/support/shared_examples/image_indexer.rb b/images/spec/support/shared_examples/image_indexer.rb index 0dc60b06e6..216dcbf191 100644 --- a/images/spec/support/shared_examples/image_indexer.rb +++ b/images/spec/support/shared_examples/image_indexer.rb @@ -1,4 +1,4 @@ -shared_examples_for 'indexes images' do +shared_examples_for 'Index' do let(:image_count) {[Refinery::Image.count, Refinery::Images.pages_per_admin_index].min} @@ -20,7 +20,7 @@ end # image index -shared_examples_for 'shows list and grid views' do +shared_examples_for 'Index Views' do let(:image_count) {[Refinery::Image.count, Refinery::Images.pages_per_admin_index].min} @@ -70,11 +70,10 @@ expect(page).to have_content(::I18n.t('switch_to', view_name: 'grid', scope: 'refinery.admin.images.index.view')) end - end # list view end -shared_examples_for 'paginates the list of images' do +shared_examples_for 'Index Pagination' do let(:image_count) {[Refinery::Image.count, Refinery::Images.pages_per_admin_index].min} diff --git a/images/spec/support/shared_examples/image_inserter.rb b/images/spec/support/shared_examples/image_inserter.rb index 60d6e002ba..d4e22c6aec 100644 --- a/images/spec/support/shared_examples/image_inserter.rb +++ b/images/spec/support/shared_examples/image_inserter.rb @@ -1,5 +1,5 @@ -shared_examples 'inserts images' do +shared_examples 'Insert' do before do raise "please set let(:initial_path)" if initial_path.blank? ensure_on(initial_path) diff --git a/images/spec/support/shared_examples/image_previewer.rb b/images/spec/support/shared_examples/image_previewer.rb index 9fe47e8ebc..2cf3a65e9f 100644 --- a/images/spec/support/shared_examples/image_previewer.rb +++ b/images/spec/support/shared_examples/image_previewer.rb @@ -9,7 +9,7 @@ def preview_image preview_window.close end -shared_examples 'shows an image preview' do +shared_examples 'Preview' do before do raise "please set let(:initial_path)" if initial_path.blank? ensure_on(initial_path) diff --git a/images/spec/support/shared_examples/image_translator.rb b/images/spec/support/shared_examples/image_translator.rb index 8341544fd5..4ab18c4049 100644 --- a/images/spec/support/shared_examples/image_translator.rb +++ b/images/spec/support/shared_examples/image_translator.rb @@ -1,4 +1,4 @@ -shared_examples 'translates an image' do +shared_examples 'Translate' do before do allow(Refinery::I18n).to receive(:frontend_locales).and_return([:en, :fr]) ensure_on(initial_path) diff --git a/images/spec/support/shared_examples/image_uploader.rb b/images/spec/support/shared_examples/image_uploader.rb index a55f6d4583..b752babc2c 100644 --- a/images/spec/support/shared_examples/image_uploader.rb +++ b/images/spec/support/shared_examples/image_uploader.rb @@ -1,34 +1,32 @@ -shared_examples 'uploads images' do +shared_examples 'Upload' do before do raise "please set let(:initial_path)" if initial_path.blank? ensure_on(initial_path) initialize_context end - let(:uploading_an_image) { - ->{ + def uploading_an_image open_upload_dialog page.within_frame(dialog_frame_id) do select_upload attach_file 'image_image', image_path - fill_in 'image_image_title', with: 'Image With Dashes' - fill_in 'image_image_alt', with: "Alt description for image" + fill_in 'image_image_title', with: 'Image With Dashes' + fill_in 'image_image_alt', with: "Alt description for image" click_button ::I18n.t('save', scope: 'refinery.admin.form_actions') end - } - } + end context 'when the image type is acceptable' do - let(:image_path) {Refinery.roots('refinery/images').join("spec/fixtures/image-with-dashes.jpg")} + let(:image_path) { Refinery.roots('refinery/images').join("spec/fixtures/image-with-dashes.jpg") } it 'the image is uploaded', :js => true do - expect(uploading_an_image).to change(Refinery::Image, :count).by(1) + expect { uploading_an_image }.to change(Refinery::Image, :count).by(1) end end context 'when the image type is not acceptable' do - let(:image_path) {Refinery.roots('refinery/images').join("spec/fixtures/cape-town-tide-table.pdf")} + let(:image_path) { Refinery.roots('refinery/images').join("spec/fixtures/cape-town-tide-table.pdf") } it 'the image is rejected', :js => true do - expect(uploading_an_image).to_not change(Refinery::Image, :count) + expect { uploading_an_image }.to_not change(Refinery::Image, :count) page.within_frame(dialog_frame_id) do expect(page).to have_content(::I18n.t('incorrect_format', :scope => 'activerecord.errors.models.refinery/image', diff --git a/images/spec/system/refinery/admin/images_spec.rb b/images/spec/system/refinery/admin/images_spec.rb index 1dc1b26945..6afa06bd67 100644 --- a/images/spec/system/refinery/admin/images_spec.rb +++ b/images/spec/system/refinery/admin/images_spec.rb @@ -13,31 +13,31 @@ module Refinery expect(page).to have_content(::I18n.t('no_images_yet', scope: 'refinery.admin.images.records')) end - it_has_behaviour 'uploads images' + it_has_behaviour 'Upload' end context 'When there is one image' do include_context 'one image' - it_has_behaviour 'indexes images' - it_has_behaviour 'shows list and grid views' - it_has_behaviour 'shows an image preview' - it_has_behaviour 'deletes an image' - it_has_behaviour 'edits an image' - it_has_behaviour 'uploads images' - it_has_behaviour 'translates an image' + it_has_behaviour 'Index' + it_has_behaviour 'Index Views' + it_has_behaviour 'Preview' + it_has_behaviour 'Delete' + it_has_behaviour 'Edit' + it_has_behaviour 'Upload' + it_has_behaviour 'Translate' end context 'When there are many images' do include_context 'many images' - it_has_behaviour 'indexes images' - it_has_behaviour 'shows list and grid views' - it_has_behaviour 'paginates the list of images' - it_has_behaviour 'shows an image preview' - it_has_behaviour 'deletes an image' - it_has_behaviour 'uploads images' - it_has_behaviour 'edits an image' + it_has_behaviour 'Index' + it_has_behaviour 'Index Views' + it_has_behaviour 'Index Pagination' + it_has_behaviour 'Preview' + it_has_behaviour 'Delete' + it_has_behaviour 'Upload' + it_has_behaviour 'Edit' end end @@ -49,25 +49,25 @@ module Refinery context 'When there are no images' do include_context 'no existing images' - it_has_behaviour 'uploads images' + it_has_behaviour 'Upload' end context 'When there is one image' do include_context 'one image' - it_has_behaviour 'indexes images' - it_has_behaviour 'paginates the list of images' - it_has_behaviour 'uploads images' - it_has_behaviour 'inserts images' + it_has_behaviour 'Index' + it_has_behaviour 'Index Pagination' + it_has_behaviour 'Upload' + it_has_behaviour 'Insert' end context 'When there are many images' do include_context 'many images' - it_has_behaviour 'indexes images' - it_has_behaviour 'paginates the list of images' - it_has_behaviour 'uploads images' - it_has_behaviour 'inserts images' + it_has_behaviour 'Index' + it_has_behaviour 'Index Pagination' + it_has_behaviour 'Upload' + it_has_behaviour 'Insert' end end diff --git a/pages/lib/refinery/pages/finder.rb b/pages/lib/refinery/pages/finder.rb index fa030d7d96..7ff2069571 100644 --- a/pages/lib/refinery/pages/finder.rb +++ b/pages/lib/refinery/pages/finder.rb @@ -44,7 +44,7 @@ def with_mobility attr_accessor :conditions def translated_attributes - Page.translated_attribute_names.map(&:to_s) | %w(locale) + [*Page.mobility_attributes, 'locale'] end def translations_conditions(original_conditions) diff --git a/pages/lib/refinery/pages/instance_methods.rb b/pages/lib/refinery/pages/instance_methods.rb index 1ff334ad96..8b2263e611 100644 --- a/pages/lib/refinery/pages/instance_methods.rb +++ b/pages/lib/refinery/pages/instance_methods.rb @@ -18,7 +18,7 @@ def error_404(exception = nil) end end - def render(*args) + def render(*args, &block) present @page unless admin? || @meta super end diff --git a/pages/refinerycms-pages.gemspec b/pages/refinerycms-pages.gemspec index c67ff1b60e..f61c19ffab 100644 --- a/pages/refinerycms-pages.gemspec +++ b/pages/refinerycms-pages.gemspec @@ -22,8 +22,8 @@ Gem::Specification.new do |s| s.add_dependency 'awesome_nested_set', '~> 3.1', '>= 3.1.0' s.add_dependency 'babosa', '~> 1.0' s.add_dependency 'diffy', '~> 3.1', '>= 3.1.0' - s.add_dependency 'friendly_id', ['>= 5.1.0', '< 5.3'] - s.add_dependency 'friendly_id-mobility', '~> 0.5' + s.add_dependency 'friendly_id', '>= 5.4.0' + s.add_dependency 'friendly_id-mobility', '~> 1.0.3' s.add_dependency 'refinerycms-core', version s.add_dependency 'seo_meta', '~> 3.0', '>= 3.0.0' s.add_dependency 'speakingurl-rails', '~> 8.0', '>= 8.0.0' diff --git a/pages/spec/controllers/refinery/pages_controller_spec.rb b/pages/spec/controllers/refinery/pages_controller_spec.rb index 2e9d86a4df..252f0782fc 100644 --- a/pages/spec/controllers/refinery/pages_controller_spec.rb +++ b/pages/spec/controllers/refinery/pages_controller_spec.rb @@ -3,7 +3,7 @@ module Refinery describe PagesController, :type => :controller do before do - FactoryBot.create(:page, link_url: "/") + FactoryBot.create(:page, { link_url: "/" }) FactoryBot.create(:page, title: "testing") FactoryBot.create(:page, link_url: "/items") end diff --git a/refinerycms.gemspec b/refinerycms.gemspec index 6a88a5b7a5..3418b4f8f2 100644 --- a/refinerycms.gemspec +++ b/refinerycms.gemspec @@ -24,6 +24,8 @@ Gem::Specification.new do |s| s.add_dependency 'refinerycms-images', version s.add_dependency 'refinerycms-pages', version s.add_dependency 'refinerycms-resources', version + + s.add_development_dependency 'rspec-rails' s.required_ruby_version = Refinery::Version.required_ruby_version s.cert_chain = [File.expand_path('certs/parndt.pem', __dir__)] diff --git a/resources/lib/refinery/resources/validators/file_size_validator.rb b/resources/lib/refinery/resources/validators/file_size_validator.rb index 9570c6253d..f881c53bfa 100644 --- a/resources/lib/refinery/resources/validators/file_size_validator.rb +++ b/resources/lib/refinery/resources/validators/file_size_validator.rb @@ -7,12 +7,11 @@ def validate(record) file = record.file if file.respond_to?(:length) && file.length > Resources.max_file_size - record.errors[:file] << ::I18n.t('too_big', - :scope => 'activerecord.errors.models.refinery/resource', - :size => Resources.max_file_size) + record.errors.add :file, ::I18n.t('too_big', + scope: 'activerecord.errors.models.refinery/resource', + size: Resources.max_file_size) end end - end end end diff --git a/resources/spec/models/refinery/resource_spec.rb b/resources/spec/models/refinery/resource_spec.rb index 2774c81709..ff647bf908 100644 --- a/resources/spec/models/refinery/resource_spec.rb +++ b/resources/spec/models/refinery/resource_spec.rb @@ -61,6 +61,7 @@ module Refinery expect(resource.title).to eq('Cape Town Tide Table') end end + context 'when a specific title has been given' do it 'returns that title' do expect(titled_resource.title).to eq('Resource Title') @@ -97,16 +98,18 @@ module Refinery end end - specify 'each returned array item should be an instance of resource' do + specify 'each returned item should be an instance of resource' do Resource.create_resources(file: [file, file, file]).each do |resource| expect(resource).to be_an_instance_of(Resource) end end - specify 'each returned array item should be passed form parameters' do - params = { file: [file, file, file], fake_param: 'blah' } + specify 'each returned array item should should be processed with other form parameters' do + params = { file: [file, file, file], file_mime_type: 'application/pdf' } - expect(Resource).to receive(:create).exactly(3).times.with(file: file, fake_param: 'blah') + expect(Resource).to receive(:create).exactly(3).times.with({file: file, + file_mime_type: 'application/pdf' + }) Resource.create_resources(params) end end diff --git a/resources/spec/system/refinery/admin/resources_spec.rb b/resources/spec/system/refinery/admin/resources_spec.rb index 65bc50b01a..a7443ea267 100644 --- a/resources/spec/system/refinery/admin/resources_spec.rb +++ b/resources/spec/system/refinery/admin/resources_spec.rb @@ -21,17 +21,15 @@ module Admin end context 'new/create' do - let(:uploading_a_file) do - lambda do - visit refinery.admin_resources_path - find('a', text: 'Upload new file').click + def uploading_a_file + visit refinery.admin_resources_path + find('a', text: 'Upload new file').click - expect(page).to have_selector 'iframe#dialog_iframe' + expect(page).to have_selector 'iframe#dialog_iframe' - page.within_frame('dialog_iframe') do - attach_file 'resource_file', file_path - click_button ::I18n.t('save', scope: 'refinery.admin.form_actions') - end + page.within_frame('dialog_iframe') do + attach_file 'resource_file', file_path + click_button ::I18n.t('save', scope: 'refinery.admin.form_actions') end end @@ -39,7 +37,7 @@ module Admin let(:file_path) { Refinery.roots('refinery/resources').join('spec/fixtures/cape-town-tide-table.pdf') } it 'the file is uploaded', js: true do - expect(uploading_a_file).to change(Refinery::Resource, :count).by(1) + expect { uploading_a_file }.to change(Refinery::Resource, :count).by(1) end end @@ -47,7 +45,7 @@ module Admin let(:file_path) { Refinery.roots('refinery/resources').join('spec/fixtures/refinery_is_secure.html') } it 'the file is rejected', js: true do - expect(uploading_a_file).to_not change(Refinery::Resource, :count) + expect { uploading_a_file }.to_not change(Refinery::Resource, :count) page.within_frame('dialog_iframe') do expect(page).to have_content(::I18n.t('incorrect_format', scope: 'activerecord.errors.models.refinery/resource')) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ffb8cbb115..f989c5c436 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -41,6 +41,7 @@ config.run_all_when_everything_filtered = true config.include ActionView::TestCase::Behavior, :file_path => %r{spec/presenters} config.infer_spec_type_from_file_location! + # config.raise_errors_for_deprecations! config.use_transactional_fixtures = true diff --git a/spec/support/refinery/generator_spec_describer.rb b/spec/support/refinery/generator_spec_describer.rb new file mode 100644 index 0000000000..ff91c8b139 --- /dev/null +++ b/spec/support/refinery/generator_spec_describer.rb @@ -0,0 +1,11 @@ +class GeneratorSpec::Matcher::File + def description + 'match a file' + end +end + +class GeneratorSpec::Matcher::Directory + def description + 'match a directory stucture' + end +end diff --git a/testing/refinerycms-testing.gemspec b/testing/refinerycms-testing.gemspec index 908cafcb7f..de4938727b 100644 --- a/testing/refinerycms-testing.gemspec +++ b/testing/refinerycms-testing.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |s| s.add_dependency 'factory_bot_rails', '~> 4.8' s.add_dependency 'rails-controller-testing', '>= 0.1.1' s.add_dependency 'refinerycms-core', version - s.add_dependency 'rspec-rails', '~> 4.0.0.beta2' + s.add_dependency 'rspec-rails', '~> 6.0.0.rc1' s.add_dependency 'webdrivers', '~> 4.0' s.required_ruby_version = Refinery::Version.required_ruby_version