Tag: 固定装置

unit testing与夹具的多态关联

我收到此错误消息: ERROR[“test_profile_display”, UsersProfileTest, 2.569931] test_profile_display#UsersProfileTest (2.57s) NoMethodError: NoMethodError: undefined method `posts’ for nil:NilClass app/controllers/users_controller.rb:14:in `show’ test/integration/users_profile_test.rb:22:in `block in ‘ app/controllers/users_controller.rb:14:in `show’ test/integration/users_profile_test.rb:22:in `block in ‘ 在@posts = @user.character.posts.paginate(page: params[:page])行中的UsersController中的character似乎是nil。 用户和角色之间存在多态关系。 我以为我在fixtures中使用了正确的语法告诉rails用户Bazley有一个fixture:在characters.yml中: character_bazley: sociable: bazley (user) 如何说服rails用户夹具确实有属于它的角色? 测试/集成/ users_profile_test.rb: require ‘test_helper’ class UsersProfileTest img.gravatar’ assert_match @user.character.posts.count.to_s, response.body assert_select ‘div.pagination’ @user.character.posts.paginate(page: 1).each do |post| assert_match post.content, response.body […]

在Rails 3项目中加载种子数据

直到现在,我一直在使用Fixtures,以及rake任务为我的数据库创建一些种子数据。 这很好用,但我突然遇到了奇怪的问题(比如在模型中获取1,2,3 ..的自动ID,然后在连接模型中输入错误的ID,使得关联根本不起作用)。 因此,我想知道更好的选择是什么。 我已经阅读了不同的内容,以及播种数据的轨道广播。 我的数据并不真正共享相同的信息。 这就像必须按原样插入的单独条目。 例如,认为我必须插入1000个具有特定能力和技能的用户。 这需要一些连接模型和一些巧妙的关联处理,如灯具。 那么,有没有比灯具方法更好的方法呢?

将灯具转换为Rails中的Factory Girl

我想将我的灯具迁移到Rails中的“Factory Girl”。 有没有简单的方法来转换factories.rb文件中的所有yml文件?

测试的未定义方法`users’

我正在尝试编写一个简单的测试,但是当我在Test函数中使用它时,我的应用程序没有检测到’users’关键字: post_controller_test.rb : require ‘test_helper’ class PostsControllerTest ‘my_id’},{‘access_token’=>Rails.application.secrets.fb_access_token}) assert_response :success end end test_helper.rb : ENV[‘RAILS_ENV’] ||= ‘test’ require File.expand_path(‘../../config/environment’, __FILE__) require ‘rails/test_help’ class ActiveSupport::TestCase include Devise::TestHelpers # Add more helper methods to be used by all tests here… end users.yml : # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html one: email: hello@testing.com encrypted_password: links: causes: two: email: […]

has_many:通过创建子after_save – > ActionView :: Template :: Error

我有三种型号:List,Food和Quantity。 列表和食物通过数量通过has_many:through关联。 模型关联正在做我想要的,但是当我测试时,会出现错误。 test_valid_list_creation_information#ListsCreateTest (1434538267.92s) ActionView::Template::Error: ActionView::Template::Error: Couldn’t find Food with ‘id’=14 app/views/lists/show.html.erb:11:in `block in _app_views_lists_show_html_erb__3286583530286700438_40342200′ app/views/lists/show.html.erb:10:in `_app_views_lists_show_html_erb__3286583530286700438_40342200’ test/integration/lists_create_test.rb:17:in `block (2 levels) in ‘ test/integration/lists_create_test.rb:16:in `block in ‘ app/views/lists/show.html.erb:11:in `block in _app_views_lists_show_html_erb__3286583530286700438_40342200′ app/views/lists/show.html.erb:10:in `_app_views_lists_show_html_erb__3286583530286700438_40342200’ test/integration/lists_create_test.rb:17:in `block (2 levels) in ‘ test/integration/lists_create_test.rb:16:in `block in ‘ 我的目标是每次创建一个列表时创建一个新的数量(与该列表相关联)。 每个数量都有amount,food_id和list_id。 list_id应该等于刚刚创建的列表的id。 food_id应该等于已经存在的随机食物的id。 金额应该是一个随机整数。 在错误中,数字14(“食物与’id’= 14)是通过从1到Food.count中随机选择一个数字生成的.Cood.count等于test / fixtures / foods.yml中的食物对象数量,所以食物肯定是被认可的,至少在我运行Food.count时。那么为什么不存在’id’= […]

Rails – 测试夹具错误NoMethodError:nil的未定义方法`type’:NilClass

我在运行使用具有模型之间关联的夹具的测试时遇到问题。 一旦我运行rake test ,这就是我得到的错误: ERROR[“test_truth”, SevenPortfolioTest, 0.005154775] test_truth#SevenPortfolioTest (0.01s) NoMethodError: NoMethodError: undefined method `type’ for nil:NilClass ERROR[“test_should_destroy_item_video”, SevenPortfolio::ItemVideosControllerTest, 0.008887804] test_should_destroy_item_video#SevenPortfolio::ItemVideosControllerTest (0.01s) NoMethodError: NoMethodError: undefined method `type’ for nil:NilClass ERROR[“test_should_get_index”, SevenPortfolio::ItemVideosControllerTest, 0.011364416] test_should_get_index#SevenPortfolio::ItemVideosControllerTest (0.01s) NoMethodError: NoMethodError: undefined method `type’ for nil:NilClass ERROR[“test_should_create_item_video”, SevenPortfolio::ItemVideosControllerTest, 0.014584266] test_should_create_item_video#SevenPortfolio::ItemVideosControllerTest (0.01s) NoMethodError: NoMethodError: undefined method `type’ for nil:NilClass ERROR[“test_should_get_new”, SevenPortfolio::ItemVideosControllerTest, 0.017282812] […]

固定装置和Selenium和Rails(哦,我的?)

您在Rails应用程序上使用Selenium测试时使用了哪些数据? 你从装置加载? 使用现有的dev db? 使用单独的(非固定)数据库? 我在考虑我的选择。 我有一个带有大型Selenium测试套件的Rails应用程序,它运行在Selenium Grid的修改版本上。 现在,部分过程是在测试套件运行之前加载一大套灯具。 这是很多数据。 其中大部分是从我们的生产数据库导出的报告信息。 当我最初设置它时,我将数据从Oracle导出到yaml。 现在一些报告表中的模式发生了变化,所以当然我必须重新生成夹具数据。 有太多的东西,手动编辑文件是不值得的。 但是,为每一个小的架构变化进行重新生成似乎效率低下 – 更不用说这是另一个值得记住的步骤。 有没有更好的办法? 编辑:我原本打算在每次测试之前加载灯具,并在每次测试后卸载它们,就像常规的Rails测试一样。 但由于此报告数据,加载灯具大约需要15分钟。 有200多个测试,套件每12小时运行一次。 我可以弯曲太空船长! 编辑2:我也同意拥有这么大的装置是难闻的气味。 我不知道如何削减它,因为报告汇总了大量数据,而selenium测试的大部分价值在于他们测试报告。 即使它只是一小部分数据,但它仍然是另一套与架构变化保持协调的集合。 (我们有一个单独的,较小的单元,function和[Rails]集成测试集。) 这让我回到原来的问题 – 除了手工制作还是记得每次重新制作它们之外还有其他选择吗?

在轨道固定装置上的ruby中的自动关联

如本文所述 ,我在fixture中使用自动关联。 例如,如果某个区域对象具有国家/地区ID,而不是执行“country_id”:1,则执行“country”:“USA”。 “USA”是我的countries.yml文件中的标签,因此灯具知道如何处理这个问题。 但是,这仅在您没有为countries对象指定ID值时才有效。 所以我不能将美国的ID指定为1.但如果我不将它指定为1,它最终会成为一些大值8974343 …这有点奇怪。 有没有办法让灯具自动生成不是超高的id? ……或者这样可以吗?

夹具会触发模型回调吗?

假设我在User.rb中有以下代码的User模型: before_create :create_dependencies after_create :build_inbox 我还有一个users.yml文件,其中定义了一堆用户装置。 当我运行rake db:fixtures:load时,它似乎不会触发回调。 这是预期的工作方式吗? 如果是这样,为什么他们这样设计呢? 有没有办法在加载灯具时强制触发回调?

Rails夹具未加载rspec

所以,我正在尝试在rails项目的上下文中学习rspec BDD测试框架。 我遇到的问题是,在我的生活中,我无法在rspec描述中正确加载我的灯具。 免责声明:是的,有比使用固定装置更好的东西。 我正在尝试一次学习一件事,这里(特别是rspec)在我玩相关工具之前,比如工厂女孩,摩卡,自动测试等。因此,我试图让死者变得简单,如果笨重,固定装置工作。 无论如何,这是代码: /test/fixtures/users.yml – # password: “secret” foo: username: foo email: foo@example.com password_hash: 3488f5f7efecab14b91eb96169e5e1ee518a569f password_salt: bef65e058905c379436d80d1a32e7374b139e7b0 bar: username: bar email: bar@example.com password_hash: 3488f5f7efecab14b91eb96169e5e1ee518a569f password_salt: bef65e058905c379436d80d1a32e7374b139e7b0 /spec/controllers/pages_controller_spec.rb – require ‘spec/spec_helper’ describe PagesController do integrate_views fixtures :users it “should render index template on index call when logged in” do session[:user_id] = user(:foo).id get […]