features/step_definitions/configuration_steps.rb in activeadmin-0.4.4 vs features/step_definitions/configuration_steps.rb in activeadmin-0.5.0.pre

- old
+ new

@@ -1,12 +1,13 @@ module ActiveAdminReloading def load_active_admin_configuration(configuration_content) + ActiveAdmin::Event.dispatch ActiveAdmin::Application::BeforeLoadEvent, ActiveAdmin.application eval(configuration_content) - ActiveAdmin::Event.dispatch ActiveAdmin::Application::LoadEvent, ActiveAdmin.application + ActiveAdmin::Event.dispatch ActiveAdmin::Application::AfterLoadEvent, ActiveAdmin.application Rails.application.reload_routes! - ActiveAdmin.application.namespaces.values.each{|n| n.load_menu! } + ActiveAdmin.application.namespaces.values.each{|n| n.reset_menu! } end end module ActiveAdminContentsRollback @@ -24,14 +25,26 @@ # Rolls the recorded files back to their original states def self.rollback! recorded_files.each do |filename, contents| # contents will be nil if the file didin't exist - if contents - File.open(filename, "w+") {|f| f << contents } + if contents.present? + File.open(filename, "w") {|f| f << contents } else File.delete(filename) + + # Delete parent directories + begin + dir = File.dirname(filename) + until dir == Rails.root + Dir.rmdir(dir) + dir = dir.split('/')[0..-2].join('/') + end + rescue Errno::ENOTEMPTY + # Directory not empty + end + end end @files = {} end @@ -44,25 +57,34 @@ ActiveAdminContentsRollback.rollback! end Given /^a configuration of:$/ do |configuration_content| load_active_admin_configuration(configuration_content) - ActiveAdmin.application.namespaces.values.each{|n| n.load_menu! } end Given /^an index configuration of:$/ do |configuration_content| load_active_admin_configuration(configuration_content) step 'I am logged in' step "I am on the index page for posts" end Given /^a show configuration of:$/ do |configuration_content| + resource = configuration_content.match(/ActiveAdmin\.register (\w+)/)[1] load_active_admin_configuration(configuration_content) - step 'I am logged in' - step "I am on the index page for posts" - step 'I follow "View"' + case resource + when "Post" + step 'I am logged in' + step "I am on the index page for posts" + step 'I follow "View"' + when "Tag" + step 'I am logged in' + Tag.create! + visit admin_tag_path(Tag.last) + else + raise "#{resource} is not supported" + end end Given /^"([^"]*)" contains:$/ do |filename, contents| require 'fileutils' filepath = Rails.root + filename