Skip to content

Commit

Permalink
Fix error when config.action_controller.raise_on_missing_callback_act…
Browse files Browse the repository at this point in the history
…ions is true
  • Loading branch information
spohlenz committed May 6, 2024
1 parent 2ec422f commit 7ca73ce
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/controllers/trestle/admin_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
class Trestle::AdminController < Trestle::ApplicationController
if respond_to?(:raise_on_missing_callback_actions=)
self.raise_on_missing_callback_actions = false
end

def index
end

Expand Down
12 changes: 12 additions & 0 deletions spec/dummy/app/admin/singular_post_admin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Trestle.resource(:singular_post, model: Post, singular: true) do
remove_action :new, :create, :edit, :destroy

instance do
model.first
end

form do |post|
text_field :title
text_area :body
end
end
5 changes: 5 additions & 0 deletions spec/dummy/config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@
# 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

# Raise error when a before_action's only/except options reference missing actions
if config.action_controller.respond_to?(:raise_on_missing_callback_actions=)
config.action_controller.raise_on_missing_callback_actions = true
end
end
5 changes: 5 additions & 0 deletions spec/dummy/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@

# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true

# Raise error when a before_action's only/except options reference missing actions
if config.action_controller.respond_to?(:raise_on_missing_callback_actions=)
config.action_controller.raise_on_missing_callback_actions = true
end
end
30 changes: 30 additions & 0 deletions spec/feature/singular_resource_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require 'spec_helper'

feature 'Singular resources' do
scenario 'show' do
create_test_post

visit '/admin/singular_post'

expect(page).to have_form("/admin/singular_post", "post") {
with_text_field "singular_post[title]", "Single Post"
with_text_area "singular_post[body]"
}
end

scenario 'update record' do
create_test_post

visit '/admin/singular_post'

fill_in "Title", with: "Updated Title"
click_button "Save Post"

expect(page).to have_content("The post was successfully updated.")
expect(page).to have_current_path(/\/admin\/singular_post/)
end

def create_test_post
Post.create!(id: 1, title: "Single Post", body: "This is a singular post", published: true)
end
end

0 comments on commit 7ca73ce

Please sign in to comment.