forked from activeadmin/activeadmin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ActiveAdmin::Resource looks up classes at runtime using their name
To deal with the reloading issues in activeadmin#870, we now store reference to the resource class as a string and constantize it each time we need it. Also added a new cucumber profile called "class-reloading" which does not cache classes. Since Active Admin should always work as expected in development with Rails reloading, we should continue to grow scenarios that include the '@requires-reloading' tag.
- Loading branch information
Showing
14 changed files
with
140 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
default: --format 'progress' --require features/support/env.rb --require features/step_definitions features | ||
wip: --format 'progress' --require features/support/env.rb --require features/step_definitions features --tags @wip:3 --wip features | ||
default: --format 'progress' --require features/support/env.rb --require features/step_definitions features --tags ~@requires-reloading | ||
wip: --format 'progress' --require features/support/env.rb --require features/step_definitions features --tags @wip:3 --wip features | ||
class-reloading: RAILS_ENV=cucumber_with_reloading --format 'progress' --require features/support/env.rb --require features/step_definitions features --tags @requires-reloading |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Feature: Development Reloading | ||
|
||
In order to quickly develop applications | ||
As a developer | ||
I want the application to reload itself in development | ||
|
||
@requires-reloading | ||
Scenario: Reloading an updated model that a resource points to | ||
Given a configuration of: | ||
""" | ||
ActiveAdmin.register Post | ||
""" | ||
And I am logged in | ||
And I create a new post with the title "" | ||
Then I should see a successful create flash | ||
Given I add "validates_presence_of :title" to the "post" model | ||
And I create a new post with the title "" | ||
Then I should not see a successful create flash | ||
And I should see a validation error "can't be blank" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
Then /^I should see a flash with "([^"]*)"$/ do |text| | ||
Then %{I should see "#{text}"} | ||
page.should have_content(text) | ||
end | ||
|
||
Then /^I should see a successful create flash$/ do | ||
page.should have_css('div.flash_notice', :text => /was successfully created/) | ||
end | ||
|
||
Then /^I should not see a successful create flash$/ do | ||
page.should_not have_css('div.flash_notice', :text => /was successfully created/) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
lib/active_admin/resource_controller/resource_class_methods.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module ActiveAdmin | ||
class ResourceController < BaseController | ||
module ResourceClassMethods | ||
|
||
# Override the default resource_class class and instance | ||
# methods to only return the class defined in the instance | ||
# of ActiveAdmin::Resource | ||
def override_resource_class_methods! | ||
self.class_eval do | ||
def self.resource_class=(klass); end | ||
|
||
def self.resource_class | ||
@active_admin_config ? @active_admin_config.resource_class : nil | ||
end | ||
|
||
def resource_class | ||
self.class.resource_class | ||
end | ||
end | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require File.expand_path('config/environments/cucumber', Rails.root) | ||
|
||
Rails.application.class.configure do | ||
config.cache_classes = false | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters