草庐IT

hdr-Build_and_test_caching

全部标签

ruby-on-rails - rails : respond_to JSON and HTML

我有一个Controller“UserController”,它应该响应对http://localhost:3000/user/3的正常请求和ajax请求。当是正常请求时,我要渲染我的View。当是AJAX请求时,我想返回JSON。正确的方法似乎是respond_todo|format|block。编写JSON很容易,但我怎样才能让它响应HTML并像往常一样简单地呈现View呢?defshow@user=User.find(params[:id])respond_todo|format|format.html{render:show????thisseemsunnecessary.Ca

ruby-on-rails - gem 更新后 : test fail with "Asset was not declared to be precompiled in production"

由于我更新了几个gem,所以所有测试都失败并出现错误:ActionView::Template::Error:Assetwasnotdeclaredtobeprecompiledinproduction.AddRails.application.config.assets.precompile+=%w(favicons/manifest.json.erb)toconfig/initializers/assets.rbandrestartyourserverapp/views/layouts/_faviconsheader.html.erb:14:in_app_views_layouts

ruby-on-rails - Rails.cache 在测试之间被清除了吗?

我们在Rails3.2应用程序中使用Rails.cache缓存id/path映射。在某些机器上它工作正常,但在其他机器上值是错误的。原因很难追踪,所以我对Rails.cache本身有一些疑问。它在测试之间被清除了吗?在开发模式下缓存的值是否有可能在测试模式下使用?如果它没有被清除,我怎么能在运行规范之前清除它呢?我的缓存存储配置是:#in:config/environments/development.rbconfig.cache_store=:memory_store,{:size=>64.megabytes}#in:config/environments/production.rb

ruby-on-rails - 错误 : Failed to build gem native extension on Mavericks

我正在尝试在OSX10.9上的Rails项目中运行bundle。到达pggem时失败并出现此错误:Gem::Installer::ExtensionBuildError:ERROR:Failedtobuildgemnativeextension./Users/kyledecot/.rvm/rubies/ruby-2.0.0-p247/bin/rubyextconf.rbcheckingforpg_config...noNopg_config...tryinganyway.Ifbuildingfails,pleasetryagainwith--with-pg-config=/path/t

ruby-on-rails - 安装 nokogiri : Failed to build gem native extension & libiconv is missing (OSX) 时出错

我尝试克隆thisrepo并运行bundleinstall。捆绑过程失败并抛出此错误:...Installingnokogiri1.6.2.1withnativeextensionsBuildingnokogiriusingpackagedlibraries.Gem::Ext::BuildError:ERROR:Failedtobuildgemnativeextension./Users/zulhilmizainudin/.rvm/rubies/ruby-2.2.0/bin/ruby-r./siteconf20151130-43880-pntnc6.rbextconf.rbBuildi

ruby-on-rails - rails : How do I write tests for a ruby module?

我想知道如何为混合到几个类中的模块编写单元测试,但不太知道如何去做:我是通过在其中一个测试文件中为包含它们的类编写测试来测试实例方法(似乎不正确),还是您能以某种方式将包含方法的测试保存在特定的单独文件中到模块?同样的问题也适用于类方法。我应该像普通Rails模型那样为模块中的每个类创建一个单独的测试文件,还是它们存在于通用模块测试文件中(如果存在)? 最佳答案 恕我直言,您应该进行涵盖模块所有用途的功能测试覆盖率,然后在单元测试中对其进行隔离测试:setupdo@object=Object.new@object.extend(Gr

ruby-on-rails - ruby rails : How do you explicitly define plural names and singular names in Rails?

例如,我使用“Bonus”作为我的模型,所以我希望“bonuses”是复数形式而“bonus”是单数形式。但是,在Ruby中,这会导致:"bonus".pluralize#bonus"bonuses".singularize#bonuse因此,例如,当我执行“has_many:bonuses”时,它不会使用Bonus.rb模型(因为Ruby需要Bonuse.rb模型)。有没有一种方法可以在RubyonRails中以某种方式更正这一点,使“bonuses”充当模型bonus.rb的复数形式? 最佳答案 在config/initiali

ruby - Ruby Koans 的test_changing_hashes 中的bonus 问题的答案是什么?

在RubyKoans,about_hashes.rb部分包含以下代码和注释:deftest_changing_hasheshash={:one=>"uno",:two=>"dos"}hash[:one]="eins"expected={:one=>"eins",:two=>"dos"}assert_equaltrue,expected==hash#BonusQuestion:Whywas"expected"brokenoutintoavariable#ratherthanusedasaliteral?end我无法在评论中找到奖金问题的答案-我尝试实际进行他们建议的替换,结果是一样的。我

ruby-on-rails - 不兼容的字符编码 : ASCII-8BIT and UTF-8

我使用Ruby1.9.2和Rails3.0.5我有以下错误:incompatiblecharacterencodings:ASCII-8BITandUTF-8我认为这与数据库无关。错误发生在View中的这一行(只是一个divhaml调用):#content全栈:ActionView::Template::Error(incompatiblecharacterencodings:ASCII-8BITandUTF-8):21:-flash.eachdo|name,msg|22:=content_tag:div,msg,:id=>"flash_#{name}"23:%div.clear24:

ruby Rspec : Testing instance variables without adding an accessor to source

我正在尝试测试以下方法:defunprocess_move(board,move)ifmove[0].instance_of?(Array)multi_move=@multi_move.pop(2).reversemulti_move.eachdo|single_move|unapply_move(board,single_move)endelseboard=unapply_move(board,move)endboardend我想为@multi_move设置状态,但我不想添加仅用于测试的访问器。有没有办法在没有访问器的情况下这样做?谢谢。 最佳答案