我正在使用Rails 4.0.0.rc2的ActiveAdmin(为Rails 4定制gemset).应用程序还具有基于railscast #385和#386的定制授权代码.
当我在ActiveAdmin资源文件中更改某些内容并尝试刷新浏览器页面时,我在该current_permission方法中收到此错误:
/ admin/courses中的ArgumentError
ApplicationController的副本已从模块树中删除但仍处于活动状态!
如果我再次尝试刷新,我得到:
自动加载常量权限时检测到循环依赖性
我认为这个问题与源文件发生变化后在开发模式下自动加载类有关.我见过类似的问题帖子,但它们适用于rails 2.3.x. 此外,解决方案似乎是unloadable在控制器中指定抛出此错误,但我不确定在ActiveAdmin中放入此代码段的位置.
这可能与ActiveAdmin无关.它可能与如何构建Permissions类及其在Application Controller中的使用有关.如果我skip_before_filter :authorize在ActiveAdmin资源类中添加一个,则此错误消失.
ApplicationController中:
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_filter :authenticate_user!
before_filter :authorize
delegate :allow_action?, to: :current_permission
helper_method :allow_action?
delegate :allow_param?, to: :current_permission
helper_method :allow_param?
private
def current_permission
@current_permission ||= Permissions.permission_for(current_user)
end
def current_resource
nil
end
def authorize …Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中使用Devise,并尝试编写更新电子邮件ID的规范.用户界面工作,但规格失败.在测试更改的电子邮件ID之前,我也在重新加载用户对象.
我观察到的一件事是在数据库上运行UPDATE USERS语句.
编写规范的正确方法是什么?
RSpec规格:
it "should update email" do
@user = subject.current_user
patch :update, id: @user, user: {:email => "john.doe@example1.com"}
@user.reload
expect(@user.email).to eq("john.doe@example1.com")
end
Run Code Online (Sandbox Code Playgroud)
RSpec错误日志:
1) Users::RegistrationsController logged in user should update email
Failure/Error: expect(@user.email).to eq("john.doe@example1.com")
expected: "john.doe@example1.com"
got: "john.doe@example.com"
(compared using ==)
Run Code Online (Sandbox Code Playgroud)
test.log中:
ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
(0.2ms) BEGIN
(0.4ms) SAVEPOINT active_record_1
User Exists (0.9ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = 'john.doe@example.com' LIMIT 1
SQL (4.1ms) INSERT INTO "users" ("created_at", "email", "encrypted_password", …Run Code Online (Sandbox Code Playgroud)