`

rails杂记

阅读更多
=======Rails2=======


用RSpec测试Authlogic的Session时,调用Session.new出现如下错误:
You must activate the Authlogic::Session::Base.controller with a controller object before creating objects

解决办法:在spec_helper.rb中添加一行代码:
Spec::Runner.configure do |config|
  #......
  config.include(Authlogic::TestCase)
end

然后在Session的测试中加一句:
before :each do
  #....
  activate_authlogic
end


===================================

RubyToolBox上看到各种Rails Fixture Replacement工具中,FactoryGirl排名第一。但是居然有这样一个问题:无论我在spec/下建立一个factories.rb文件或者是在spec/factories/下建立一个*.rb文件,FactoryGirl都无法加载到,最后看源代:
if defined? Rails.configuration
  Rails.configuration.after_initialize do
    Factory.definition_file_paths = [
      File.join(RAILS_ROOT, 'test', 'factories'),
      File.join(RAILS_ROOT, 'spec', 'factories')
    ]
    Factory.find_definitions
  end
else
  Factory.find_definitions
end

发现这个after_initialize方法中的block不会执行,估计是测试环境不会触发这个after_initialize。搜索到这个帖子:http://groups.google.com/group/factory_girl/browse_thread/thread/8add0361e717c240
由于访问google group需要特殊技能,所以copy一份过来:
ook?ook! 写道
Just try: it doesn't, but thank you for the idea.

I'm reading the lib bootstrapper, and it looks like Factory add its
definition file only when Rails is loaded. Debugging the thing, I'm
realizing that Rails.configuration is not yet instance, meaning that I'm not
requiring FG where it expect it.

Trying to initiate FG in environments/test lead to correct beahvior, but why
preventing FG to load factories if not in Rails? It's not a big deal, but I
think FG should load its definition path even if not in a standard Rails
way… I think I'll propose a patch where FG tolerate the fact FG is not
require in environnment.

RFC?

由于是上班时间,没有空多作研究,暂时先把代码注释掉一些:
#if defined? Rails.configuration
#  Rails.configuration.after_initialize do
    Factory.definition_file_paths = [
      File.join(RAILS_ROOT, 'test', 'factories'),
      File.join(RAILS_ROOT, 'spec', 'factories')
    ]
    Factory.find_definitions
#  end
#else
#  Factory.find_definitions
#end

使用正常。
分享到:
评论
1 楼 yuan 2010-05-10  
delayed_job 2.0.0 ~ 2.0.3存在问题,可用的最新版本号为1.8.5。
searchlogic2.4.x 在调用form.check_box时报错:undefined method to_id。目前可用的最新版本为2.3.5。

相关推荐

    rails 2.3.2离线安装rails 2.3.2离线安装

    rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails 2.3.2离线安装rails ...

    [Rails] Crafting Rails Applications (英文版)

    [Pragmatic Bookshelf] Crafting Rails Applications Expert Practices for Everyday Rails Development (E-Book) ☆ 图书概要:☆ Rails 3 is a huge step forward. You can now easily extend the framework, ...

    Ruby on Rails Guides v2 - Ruby on Rails 4.2.5

    Ruby on Rails Guides v2 - Ruby on Rails 4.2.5

    Ruby on Rails Tutorial

    《Ruby on Rails Tutorial》中文版(原书第2版,涵盖 Rails 4) Ruby 是一门很美的计算机语言,其设计原则就是“让编程人员快乐”。David Heinemeier Hansson 就是看重了这一点,才在开发 Rails 框架时选择了 Ruby...

    Rails之道,完整扫描版

    《Rails之道》按照Rails的各个子系统进行组织编排,分别介绍了Rails的环境、初始过程、配置和日志记录,Rails的分配器、控制器、页面生成和路由,REST、资源和Rails,ActiveRecord的基础、关联、验证和高级技巧,...

    Rails项目源代码

    一个用Ruby on Rails搭建的图片分享的网站项目.完整源代码

    rails敏捷开发的购物车系统

    本资源是参照rails敏捷开发第四版书中的例子,rails的版本是rails3.2.6

    Bootstrap for Rails (2015)

    Bootstrap 3 和 Rails 4(样例用的是Ruby 2.1.1,Rails 4.1.4) Table of Contents Preface 1 Chapter 1: Introducing Web Application Development in Rails 7 Why Bootstrap with Rails? 8 Setting up a Todo ...

    adminlte-rails, AdminLTE Rails gem 将AdminLTE主题与 Rails 资产管道集成.zip

    adminlte-rails, AdminLTE Rails gem 将AdminLTE主题与 Rails 资产管道集成 AdminLTE Rails gem AdminLTE 是后端的高级 Bootstrap 主题。英镑 AdminLTE Rails gem 与 Rails 资产管道集成了英镑AdminLTE主题。安装将...

    Agile Web Development with Rails 4

    Ruby on Rails helps you produce high-quality, beautiful-looking web applications quickly. You concentrate on creating the application, and Rails takes care of the details., Tens of thousands of ...

    Rails101_by_rails4.0

    中文世界唯一一本Rails 4.0.0 + Ruby 2.0.0 的自學書籍

    使用Aptana+Rails开发Rails Web应用(中文)

    使用Aptana+Rails开发Rails Web应用 有Aptana的安装配置等等,中文

    rails api(文档)

    rails文档 rails api 英文

    提升Ruby on Rails性能的几个解决方案

    Ruby On Rails 框架自它提出之日起就受到广泛关注,在“不要重复自己”,“约定优于配置”等思想的指导下,Rails 带给 Web 开发者的是极高的开发效率。 ActiveRecord 的灵活让你再也不用配置繁琐的 Hibernate 即可...

    rails指南 中文版

    rails指南 中文版

    minitest-rails, Rails的Minitest集成.zip

    minitest-rails, Rails的Minitest集成 minitestRails 5的Minitest集成 安装gem install minitest-rails这将安装以下宝石:minitest配置创建一个新的Rail

    rails金典教材3本

    Ruby+on+Rails+3+Tutorial.pdf 应用Rails进行敏捷Web开发第4版.pdf (Agile Web Development with Rails) Rails.Recipes.Rails.3.Edition.pdf

    Learning Rails 5(高清文字pdf版)

    If you’re a web developer or designer ready to learn Ruby on Rails, this hands-on guide is the ideal way to get started. Rather than toss you into the middle of the framework’s Model-View-Controller...

Global site tag (gtag.js) - Google Analytics