From 940643e1c3cd1718ea15a9bf0b3393eeb97d926a Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 17 Aug 2017 00:18:43 +0200 Subject: [PATCH 1/5] Allow Rails 5.1 as well --- alchemy_cms.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alchemy_cms.gemspec b/alchemy_cms.gemspec index 6ba4afa1a4..df1bc5cbc4 100644 --- a/alchemy_cms.gemspec +++ b/alchemy_cms.gemspec @@ -33,7 +33,7 @@ Gem::Specification.new do |gem| gem.add_runtime_dependency 'kaminari', ['~> 0.15'] gem.add_runtime_dependency 'originator', ['~> 3.0'] gem.add_runtime_dependency 'non-stupid-digest-assets', ['~> 1.0.8'] - gem.add_runtime_dependency 'rails', ['~> 5.0.0'] + gem.add_runtime_dependency 'rails', ['~> 5.0', '< 6.0'] gem.add_runtime_dependency 'ransack', ['~> 1.4'] gem.add_runtime_dependency 'request_store', ['~> 1.2'] gem.add_runtime_dependency 'responders', ['~> 2.0'] From f029a1205149da35ce316e1571acd3a69739e99e Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 17 Aug 2017 00:21:41 +0200 Subject: [PATCH 2/5] Update dummy test app to Rails 5.1 --- Gemfile | 1 + spec/dummy/config/application.rb | 5 + spec/dummy/config/environments/development.rb | 4 +- spec/dummy/config/environments/production.rb | 7 +- .../new_framework_defaults_5_1.rb | 14 + spec/dummy/db/schema.rb | 350 +++++++++--------- 6 files changed, 203 insertions(+), 178 deletions(-) create mode 100644 spec/dummy/config/initializers/new_framework_defaults_5_1.rb diff --git a/Gemfile b/Gemfile index 24fd9b7bc8..2959a140ed 100644 --- a/Gemfile +++ b/Gemfile @@ -27,6 +27,7 @@ group :development, :test do gem 'spring' gem 'spring-commands-rspec' gem 'rubocop', require: false + gem 'listen' end gem 'capybara', '~> 2.4' gem 'database_cleaner', '~> 1.3' diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb index 981fc675f5..e7c5cae1f3 100644 --- a/spec/dummy/config/application.rb +++ b/spec/dummy/config/application.rb @@ -10,11 +10,16 @@ # require "action_cable/engine" # require "rails/test_unit/railtie" +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) require "alchemy_cms" module Dummy class Application < Rails::Application + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 5.1 + # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. diff --git a/spec/dummy/config/environments/development.rb b/spec/dummy/config/environments/development.rb index e64889cdb3..5187e22186 100644 --- a/spec/dummy/config/environments/development.rb +++ b/spec/dummy/config/environments/development.rb @@ -18,7 +18,7 @@ config.cache_store = :memory_store config.public_file_server.headers = { - 'Cache-Control' => 'public, max-age=172800' + 'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}" } else config.action_controller.perform_caching = false @@ -50,5 +50,5 @@ # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. - # config.file_watcher = ActiveSupport::EventedFileUpdateChecker + config.file_watcher = ActiveSupport::EventedFileUpdateChecker end diff --git a/spec/dummy/config/environments/production.rb b/spec/dummy/config/environments/production.rb index 739e81cb35..6ea0018626 100644 --- a/spec/dummy/config/environments/production.rb +++ b/spec/dummy/config/environments/production.rb @@ -14,6 +14,11 @@ config.consider_all_requests_local = false config.action_controller.perform_caching = true + # Attempt to read encrypted secrets from `config/secrets.yml.enc`. + # Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or + # `config/secrets.yml.key`. + config.read_encrypted_secrets = true + # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? @@ -78,7 +83,7 @@ if ENV["RAILS_LOG_TO_STDOUT"].present? logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter - config.logger = ActiveSupport::TaggedLogging.new(logger) + config.logger = ActiveSupport::TaggedLogging.new(logger) end # Do not dump schema after migrations. diff --git a/spec/dummy/config/initializers/new_framework_defaults_5_1.rb b/spec/dummy/config/initializers/new_framework_defaults_5_1.rb new file mode 100644 index 0000000000..9010abd5c2 --- /dev/null +++ b/spec/dummy/config/initializers/new_framework_defaults_5_1.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 5.1 upgrade. +# +# Once upgraded flip defaults one by one to migrate to the new default. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. + +# Make `form_with` generate non-remote forms. +Rails.application.config.action_view.form_with_generates_remote_forms = false + +# Unknown asset fallback will return the path passed in when the given +# asset is not present in the asset pipeline. +# Rails.application.config.assets.unknown_asset_fallback = false diff --git a/spec/dummy/db/schema.rb b/spec/dummy/db/schema.rb index 7dd495d0b1..3226b62317 100644 --- a/spec/dummy/db/schema.rb +++ b/spec/dummy/db/schema.rb @@ -13,55 +13,55 @@ ActiveRecord::Schema.define(version: 20160928080104) do create_table "alchemy_attachments", force: :cascade do |t| - t.string "name" - t.string "file_name" - t.string "file_mime_type" - t.integer "file_size" - t.integer "creator_id" - t.integer "updater_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.text "cached_tag_list" - t.string "file_uid" + t.string "name" + t.string "file_name" + t.string "file_mime_type" + t.integer "file_size" + t.integer "creator_id" + t.integer "updater_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.text "cached_tag_list" + t.string "file_uid" t.index ["file_uid"], name: "index_alchemy_attachments_on_file_uid" end create_table "alchemy_cells", force: :cascade do |t| - t.integer "page_id", null: false - t.string "name" + t.integer "page_id", null: false + t.string "name" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["page_id"], name: "index_alchemy_cells_on_page_id" end create_table "alchemy_contents", force: :cascade do |t| - t.string "name" - t.string "essence_type", null: false - t.integer "essence_id", null: false - t.integer "element_id", null: false - t.integer "position" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "creator_id" - t.integer "updater_id" + t.string "name" + t.string "essence_type", null: false + t.integer "essence_id", null: false + t.integer "element_id", null: false + t.integer "position" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "creator_id" + t.integer "updater_id" t.index ["element_id", "position"], name: "index_contents_on_element_id_and_position" t.index ["essence_id", "essence_type"], name: "index_alchemy_contents_on_essence_id_and_essence_type", unique: true end create_table "alchemy_elements", force: :cascade do |t| - t.string "name" - t.integer "position" - t.integer "page_id", null: false - t.boolean "public", default: true - t.boolean "folded", default: false - t.boolean "unique", default: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "creator_id" - t.integer "updater_id" - t.integer "cell_id" - t.text "cached_tag_list" - t.integer "parent_element_id" + t.string "name" + t.integer "position" + t.integer "page_id", null: false + t.boolean "public", default: true + t.boolean "folded", default: false + t.boolean "unique", default: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "creator_id" + t.integer "updater_id" + t.integer "cell_id" + t.text "cached_tag_list" + t.integer "parent_element_id" t.index ["cell_id"], name: "index_alchemy_elements_on_cell_id" t.index ["page_id", "parent_element_id"], name: "index_alchemy_elements_on_page_id_and_parent_element_id" t.index ["page_id", "position"], name: "index_elements_on_page_id_and_position" @@ -73,134 +73,134 @@ end create_table "alchemy_essence_booleans", force: :cascade do |t| - t.boolean "value" + t.boolean "value" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.integer "creator_id" - t.integer "updater_id" + t.integer "creator_id" + t.integer "updater_id" t.index ["value"], name: "index_alchemy_essence_booleans_on_value" end create_table "alchemy_essence_dates", force: :cascade do |t| t.datetime "date" - t.integer "creator_id" - t.integer "updater_id" + t.integer "creator_id" + t.integer "updater_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false end create_table "alchemy_essence_files", force: :cascade do |t| - t.integer "attachment_id" - t.string "title" - t.string "css_class" - t.integer "creator_id" - t.integer "updater_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "link_text" + t.integer "attachment_id" + t.string "title" + t.string "css_class" + t.integer "creator_id" + t.integer "updater_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "link_text" t.index ["attachment_id"], name: "index_alchemy_essence_files_on_attachment_id" end create_table "alchemy_essence_htmls", force: :cascade do |t| - t.text "source" - t.integer "creator_id" - t.integer "updater_id" + t.text "source" + t.integer "creator_id" + t.integer "updater_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false end create_table "alchemy_essence_links", force: :cascade do |t| - t.string "link" - t.string "link_title" - t.string "link_target" - t.string "link_class_name" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "creator_id" - t.integer "updater_id" + t.string "link" + t.string "link_title" + t.string "link_target" + t.string "link_class_name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "creator_id" + t.integer "updater_id" end create_table "alchemy_essence_pictures", force: :cascade do |t| - t.integer "picture_id" - t.string "caption" - t.string "title" - t.string "alt_tag" - t.string "link" - t.string "link_class_name" - t.string "link_title" - t.string "css_class" - t.string "link_target" - t.integer "creator_id" - t.integer "updater_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "crop_from" - t.string "crop_size" - t.string "render_size" + t.integer "picture_id" + t.string "caption" + t.string "title" + t.string "alt_tag" + t.string "link" + t.string "link_class_name" + t.string "link_title" + t.string "css_class" + t.string "link_target" + t.integer "creator_id" + t.integer "updater_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "crop_from" + t.string "crop_size" + t.string "render_size" t.index ["picture_id"], name: "index_alchemy_essence_pictures_on_picture_id" end create_table "alchemy_essence_richtexts", force: :cascade do |t| - t.text "body" - t.text "stripped_body" - t.boolean "public" - t.integer "creator_id" - t.integer "updater_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.text "body" + t.text "stripped_body" + t.boolean "public" + t.integer "creator_id" + t.integer "updater_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "alchemy_essence_selects", force: :cascade do |t| - t.string "value" + t.string "value" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.integer "creator_id" - t.integer "updater_id" + t.integer "creator_id" + t.integer "updater_id" t.index ["value"], name: "index_alchemy_essence_selects_on_value" end create_table "alchemy_essence_texts", force: :cascade do |t| - t.text "body" - t.string "link" - t.string "link_title" - t.string "link_class_name" - t.boolean "public", default: false - t.string "link_target" - t.integer "creator_id" - t.integer "updater_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.text "body" + t.string "link" + t.string "link_title" + t.string "link_class_name" + t.boolean "public", default: false + t.string "link_target" + t.integer "creator_id" + t.integer "updater_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "alchemy_folded_pages", force: :cascade do |t| - t.integer "page_id", null: false - t.integer "user_id", null: false - t.boolean "folded", default: false + t.integer "page_id", null: false + t.integer "user_id", null: false + t.boolean "folded", default: false t.index ["page_id", "user_id"], name: "index_alchemy_folded_pages_on_page_id_and_user_id", unique: true end create_table "alchemy_languages", force: :cascade do |t| - t.string "name" - t.string "language_code" - t.string "frontpage_name" - t.string "page_layout", default: "intro" - t.boolean "public", default: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "creator_id" - t.integer "updater_id" - t.boolean "default", default: false - t.string "country_code", default: "", null: false - t.integer "site_id", null: false - t.string "locale" + t.string "name" + t.string "language_code" + t.string "frontpage_name" + t.string "page_layout", default: "intro" + t.boolean "public", default: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "creator_id" + t.integer "updater_id" + t.boolean "default", default: false + t.string "country_code", default: "", null: false + t.integer "site_id", null: false + t.string "locale" t.index ["language_code", "country_code"], name: "index_alchemy_languages_on_language_code_and_country_code" t.index ["language_code"], name: "index_alchemy_languages_on_language_code" t.index ["site_id"], name: "index_alchemy_languages_on_site_id" end create_table "alchemy_legacy_page_urls", force: :cascade do |t| - t.string "urlname", null: false - t.integer "page_id", null: false + t.string "urlname", null: false + t.integer "page_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["page_id"], name: "index_alchemy_legacy_page_urls_on_page_id" @@ -208,31 +208,31 @@ end create_table "alchemy_pages", force: :cascade do |t| - t.string "name" - t.string "urlname" - t.string "title" - t.string "language_code" - t.boolean "language_root" - t.string "page_layout" - t.text "meta_keywords" - t.text "meta_description" - t.integer "lft" - t.integer "rgt" - t.integer "parent_id" - t.integer "depth" - t.boolean "visible", default: false - t.integer "locked_by" - t.boolean "restricted", default: false - t.boolean "robot_index", default: true - t.boolean "robot_follow", default: true - t.boolean "sitemap", default: true - t.boolean "layoutpage", default: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "creator_id" - t.integer "updater_id" - t.integer "language_id" - t.text "cached_tag_list" + t.string "name" + t.string "urlname" + t.string "title" + t.string "language_code" + t.boolean "language_root" + t.string "page_layout" + t.text "meta_keywords" + t.text "meta_description" + t.integer "lft" + t.integer "rgt" + t.integer "parent_id" + t.integer "depth" + t.boolean "visible", default: false + t.integer "locked_by" + t.boolean "restricted", default: false + t.boolean "robot_index", default: true + t.boolean "robot_follow", default: true + t.boolean "sitemap", default: true + t.boolean "layoutpage", default: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "creator_id" + t.integer "updater_id" + t.integer "language_id" + t.text "cached_tag_list" t.datetime "published_at" t.datetime "public_on" t.datetime "public_until" @@ -246,29 +246,29 @@ end create_table "alchemy_pictures", force: :cascade do |t| - t.string "name" - t.string "image_file_name" - t.integer "image_file_width" - t.integer "image_file_height" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "creator_id" - t.integer "updater_id" - t.string "upload_hash" - t.text "cached_tag_list" - t.string "image_file_uid" - t.integer "image_file_size" - t.string "image_file_format" + t.string "name" + t.string "image_file_name" + t.integer "image_file_width" + t.integer "image_file_height" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "creator_id" + t.integer "updater_id" + t.string "upload_hash" + t.text "cached_tag_list" + t.string "image_file_uid" + t.integer "image_file_size" + t.string "image_file_format" end create_table "alchemy_sites", force: :cascade do |t| - t.string "host" - t.string "name" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.boolean "public", default: false - t.text "aliases" - t.boolean "redirect_to_primary_host" + t.string "host" + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.boolean "public", default: false + t.text "aliases" + t.boolean "redirect_to_primary_host" t.index ["host", "public"], name: "alchemy_sites_public_hosts_idx" t.index ["host"], name: "index_alchemy_sites_on_host" end @@ -284,33 +284,33 @@ end create_table "events", force: :cascade do |t| - t.string "name" - t.string "hidden_name" + t.string "name" + t.string "hidden_name" t.datetime "starts_at" t.datetime "ends_at" - t.time "lunch_starts_at" - t.time "lunch_ends_at" - t.text "description" - t.decimal "entrance_fee", precision: 6, scale: 2 - t.boolean "published" - t.integer "location_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.time "lunch_starts_at" + t.time "lunch_ends_at" + t.text "description" + t.decimal "entrance_fee", precision: 6, scale: 2 + t.boolean "published" + t.integer "location_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "locations", force: :cascade do |t| - t.string "name" + t.string "name" t.datetime "created_at" t.datetime "updated_at" end create_table "taggings", force: :cascade do |t| - t.integer "tag_id" - t.string "taggable_type" - t.integer "taggable_id" - t.string "tagger_type" - t.integer "tagger_id" - t.string "context", limit: 128 + t.integer "tag_id" + t.string "taggable_type" + t.integer "taggable_id" + t.string "tagger_type" + t.integer "tagger_id" + t.string "context", limit: 128 t.datetime "created_at" t.index ["context"], name: "index_taggings_on_context" t.index ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true @@ -324,7 +324,7 @@ end create_table "tags", force: :cascade do |t| - t.string "name" + t.string "name" t.integer "taggings_count", default: 0 t.index ["name"], name: "index_tags_on_name", unique: true end From c3f72cc4d4b5255baac1203c357fb05758c4266a Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 17 Aug 2017 00:22:36 +0200 Subject: [PATCH 3/5] Fixes elements tag helper Rails 5.1 removed (without deprecation notice!) the `tag_options` helper and move it to the `tag_builder` object. --- app/helpers/alchemy/elements_helper.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/helpers/alchemy/elements_helper.rb b/app/helpers/alchemy/elements_helper.rb index 97b6075a96..08b478c11f 100644 --- a/app/helpers/alchemy/elements_helper.rb +++ b/app/helpers/alchemy/elements_helper.rb @@ -187,7 +187,12 @@ def element_dom_id(element) # Renders the HTML tag attributes required for preview mode. def element_preview_code(element) - tag_options(element_preview_code_attributes(element)) + if respond_to?(:tag_options) + tag_options(element_preview_code_attributes(element)) + else + # Rails 5.1 uses TagBuilder + tag_builder.tag_options(element_preview_code_attributes(element)) + end end # Returns a hash containing the HTML tag attributes required for preview mode. @@ -205,7 +210,12 @@ def element_preview_code_attributes(element) # HTML tag attributes containing the element's tag information. # def element_tags(element, options = {}) - tag_options(element_tags_attributes(element, options)) + if respond_to?(:tag_options) + tag_options(element_tags_attributes(element, options)) + else + # Rails 5.1 uses TagBuilder + tag_builder.tag_options(element_tags_attributes(element, options)) + end end # Returns the element's tags information as an attribute hash. From 91826f4e1806cd23ca1be3c5ef0d72ed791f73ec Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 7 Sep 2017 12:02:58 +0200 Subject: [PATCH 4/5] Use originator 3.1 gem for Rails 5.1 compatibility --- alchemy_cms.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alchemy_cms.gemspec b/alchemy_cms.gemspec index df1bc5cbc4..d3bcf40295 100644 --- a/alchemy_cms.gemspec +++ b/alchemy_cms.gemspec @@ -31,7 +31,7 @@ Gem::Specification.new do |gem| gem.add_runtime_dependency 'jquery-rails', ['~> 4.0'] gem.add_runtime_dependency 'jquery-ui-rails', ['~> 5.0.0'] gem.add_runtime_dependency 'kaminari', ['~> 0.15'] - gem.add_runtime_dependency 'originator', ['~> 3.0'] + gem.add_runtime_dependency 'originator', ['~> 3.1'] gem.add_runtime_dependency 'non-stupid-digest-assets', ['~> 1.0.8'] gem.add_runtime_dependency 'rails', ['~> 5.0', '< 6.0'] gem.add_runtime_dependency 'ransack', ['~> 1.4'] From 5a0f167c3a2b06e82d045d129b55e1bb86e8d07c Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 7 Sep 2017 12:15:07 +0200 Subject: [PATCH 5/5] Fixes resource specs The dummy apps `Event` model has a `belongs_to` `Location` relation that is mandatory since Rails 5.1. This changes the specs so we always have a location for an event. --- .../alchemy/admin/resources_controller_spec.rb | 13 +++++++------ spec/factories.rb | 5 +++++ spec/features/admin/resources_integration_spec.rb | 3 +++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/spec/controllers/alchemy/admin/resources_controller_spec.rb b/spec/controllers/alchemy/admin/resources_controller_spec.rb index 09eed7c3fc..f844502335 100644 --- a/spec/controllers/alchemy/admin/resources_controller_spec.rb +++ b/spec/controllers/alchemy/admin/resources_controller_spec.rb @@ -10,8 +10,8 @@ class Admin::EventsController < Alchemy::Admin::ResourcesController describe '#index' do let(:params) { Hash.new } - let!(:peter) { Event.create(name: 'Peter') } - let!(:lustig) { Event.create(name: 'Lustig') } + let!(:peter) { create(:event, name: 'Peter') } + let!(:lustig) { create(:event, name: 'Lustig') } before do authorize_user(:as_admin) @@ -33,7 +33,7 @@ class Admin::EventsController < Alchemy::Admin::ResourcesController end context "but searching for record with certain association" do - let(:bauwagen) { Location.create(name: 'Bauwagen') } + let(:bauwagen) { create(:location, name: 'Bauwagen') } let(:params) { {q: {name_or_hidden_name_or_location_name_cont: "Bauwagen"}} } before do @@ -52,7 +52,7 @@ class Admin::EventsController < Alchemy::Admin::ResourcesController describe '#update' do let(:params) { {q: 'some_query', page: 6} } - let!(:peter) { Event.create(name: 'Peter') } + let!(:peter) { create(:event, name: 'Peter') } it 'redirects to index, keeping the current location parameters' do post :update, params: {id: peter.id, event: {name: "Hans"}}.merge(params) @@ -62,16 +62,17 @@ class Admin::EventsController < Alchemy::Admin::ResourcesController describe '#create' do let(:params) { {q: 'some_query', page: 6} } + let!(:location) { create(:location) } it 'redirects to index, keeping the current location parameters' do - post :create, params: {event: {name: "Hans"}}.merge(params) + post :create, params: {event: {name: "Hans", location_id: location.id}}.merge(params) expect(response.redirect_url).to eq("http://test.host/admin/events?page=6&q=some_query") end end describe '#destroy' do let(:params) { {q: 'some_query', page: 6} } - let!(:peter) { Event.create(name: 'Peter') } + let!(:peter) { create(:event, name: 'Peter') } it 'redirects to index, keeping the current location parameters' do delete :destroy, params: {id: peter.id}.merge(params) diff --git a/spec/factories.rb b/spec/factories.rb index d7f665212e..b919db55f4 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -2,6 +2,7 @@ factory :event do name 'My Event' hidden_name 'not shown' + location starts_at DateTime.new(2012, 03, 02, 8, 15) ends_at DateTime.new(2012, 03, 02, 19, 30) lunch_starts_at DateTime.new(2012, 03, 02, 12, 15) @@ -10,4 +11,8 @@ published false entrance_fee 12.3 end + + factory :location do + name 'Awesome Lodge' + end end diff --git a/spec/features/admin/resources_integration_spec.rb b/spec/features/admin/resources_integration_spec.rb index 9374f0483c..2458080a77 100644 --- a/spec/features/admin/resources_integration_spec.rb +++ b/spec/features/admin/resources_integration_spec.rb @@ -57,10 +57,13 @@ def reload_event_class describe "create resource item" do context "when form filled with valid data" do + let!(:location) { create(:location) } + before do visit '/admin/events/new' fill_in 'event_name', with: 'My second event' fill_in 'event_starts_at', with: DateTime.new(2012, 03, 03, 20, 00) + select location.name, from: 'Location' click_on 'Save' end