我有一个小的Rails 4.0.0/Ruby 2.0.0-p247应用程序,我想写一些测试.我跑的时候
rake cucumber:all
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
/Users/me/.rvm/rubies/ruby-2.0.0-p247/bin/ruby -S bundle exec cucumber --profile default
/Users/me/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/json/common.rb:155:in `parse': uninitialized constant JSON::Parser (NameError)
from /Users/me/.rvm/gems/ruby-2.0.0-p247/gems/multi_json-1.7.8/lib/multi_json/adapters/json_common.rb:16:in `load'
from /Users/me/.rvm/gems/ruby-2.0.0-p247/gems/multi_json-1.7.8/lib/multi_json/adapter.rb:19:in `load'
from /Users/me/.rvm/gems/ruby-2.0.0-p247/gems/multi_json-1.7.8/lib/multi_json.rb:118:in `load'
from /Users/me/.rvm/gems/ruby-2.0.0-p247/gems/gherkin-2.12.0/lib/gherkin/i18n.rb:14:in `<class:I18n>'
from /Users/me/.rvm/gems/ruby-2.0.0-p247/gems/gherkin-2.12.0/lib/gherkin/i18n.rb:6:in `<module:Gherkin>'
from /Users/me/.rvm/gems/ruby-2.0.0-p247/gems/gherkin-2.12.0/lib/gherkin/i18n.rb:5:in `<top (required)>'
from /Users/me/.rvm/gems/ruby-2.0.0-p247/gems/gherkin-2.12.0/lib/gherkin/lexer/i18n_lexer.rb:2:in `require'
from /Users/me/.rvm/gems/ruby-2.0.0-p247/gems/gherkin-2.12.0/lib/gherkin/lexer/i18n_lexer.rb:2:in `<top (required)>'
from /Users/me/.rvm/gems/ruby-2.0.0-p247/gems/gherkin-2.12.0/lib/gherkin.rb:1:in `require'
from /Users/me/.rvm/gems/ruby-2.0.0-p247/gems/gherkin-2.12.0/lib/gherkin.rb:1:in `<top (required)>'
from /Users/me/.rvm/gems/ruby-2.0.0-p247/gems/cucumber-1.3.5/lib/cucumber/cli/main.rb:2:in `require'
from /Users/me/.rvm/gems/ruby-2.0.0-p247/gems/cucumber-1.3.5/lib/cucumber/cli/main.rb:2:in `<top (required)>'
from /Users/me/.rvm/gems/ruby-2.0.0-p247/gems/cucumber-1.3.5/bin/cucumber:11:in `require'
from /Users/me/.rvm/gems/ruby-2.0.0-p247/gems/cucumber-1.3.5/bin/cucumber:11:in `<top (required)>'
from /Users/me/.rvm/gems/ruby-2.0.0-p247/bin/cucumber:23:in `load'
from /Users/me/.rvm/gems/ruby-2.0.0-p247/bin/cucumber:23:in `<main>'
from /Users/me/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `eval'
from /Users/me/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `<main>'
Run Code Online (Sandbox Code Playgroud)
我运行捆绑安装,捆绑更新,宝石清理等无济于事.这个相同的Rails应用程序在另一台机器(Mac OS …
我想在Rails 4.0.0应用程序中使用Paperclip将视频文件添加到Episode模型中.但是,当我在创建操作(第二行)中调用episode_params时,我收到错误"没有将符号隐式转换为哈希":
def create
@episode = Episode.new(episode_params)
respond_to do |format|
if @episode.save
format.html { redirect_to @episode, notice: 'Episode was successfully created.' }
format.json { render action: 'show', status: :created, location: @episode }
else
format.html { render action: 'new' }
format.json { render json: @episode.errors, status: :unprocessable_entity }
end
end
Run Code Online (Sandbox Code Playgroud)
结束
我的episode_params方法:
def episode_params
params.require(:episode).permit(:name, :number, :description, :tag_list, :video => [:tempfile, :original_filename, :content_type, :headers])
end
Run Code Online (Sandbox Code Playgroud)
并且参数哈希:
{"utf8"=>"?", "authenticity_token"=>"VbOJvzWjlXMHOYpYMkwXUfdUxm9OcQx3LTMIJzk5eJQ=", "episode"=>{"name"=>"Test Episode 2", "number"=>"2", "description"=>"Testing Paperclip with video files", "tag_list"=>"test, file, video", "video"=>#<ActionDispatch::Http::UploadedFile:0x007fec361a80e0 …Run Code Online (Sandbox Code Playgroud) 我有一个Rails 4应用程序,当我运行Brakeman时,它(正确地)在我的创建操作中标识了一个不受保护的重定向.但是,添加only_path:true(如在Brakeman Railscast中)并不能解决警告:
def create
refer_url = params[:referrer]
@portfolio = current_user.portfolios.build(portfolio_params)
if @portfolio.save
redirect_to refer_url, notice: "Portfolio was successfully created.", only_path: true
else
render :new
end
end
Run Code Online (Sandbox Code Playgroud)
结果是:
+SECURITY WARNINGS+
+------------+-----------------------+---------+--------------+----------------------------------------------------------------------------------------------------------------------->>
| Confidence | Class | Method | Warning Type | Message >>
+------------+-----------------------+---------+--------------+----------------------------------------------------------------------------------------------------------------------->>
| High | PortfoliosController | create | Redirect | Possible unprotected redirect near line 14: redirect_to(+params[:referrer]+, :notice => "Portfolio was successfully cr>>
+------------+-----------------------+---------+--------------+----------------------------------------------------------------------------------------------------------------------->>
Run Code Online (Sandbox Code Playgroud)
为什么会这样?Brakeman还在识别什么风险?
我正在尝试使用Factory Girl生成具有多态依赖项的模型实例.例如,属性可以具有_one假设,租户可以具有假设,而属性可以具有多个租户.我想使用Factory Girl生成:property_with_assumption或a:tenant_with_assumption.
我可以使用属性做到这一点没有问题:
FactoryGirl.define do
factory :property do
...fields...
end
factory :property_with_assumption do
after(:create) do |property|
FactoryGirl.create(:assumption, assumable: property)
end
end
end
Run Code Online (Sandbox Code Playgroud)
我对租户有类似的定义:
FactoryGirl.define do
factory :tenant, :class => 'Tenant' do
...fields...
end
factory :tenant_with_assumption do
after(:create) do |tenant|
FactoryGirl.create(:assumption, assumable: tenant)
end
end
end
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试
FactoryGirl.create(:tenant_with_assumption, property: [valid property])
Run Code Online (Sandbox Code Playgroud)
我明白了
NameError: uninitialized constant TenantWithAssumption
Run Code Online (Sandbox Code Playgroud)
为什么它适用于一种型号而不适用于另一种型号?提前致谢.
我在Rails 4中使用Factory Girl获得了"Factory not registered"错误.这是我在spec/factories/user.rb中为一个简单的Devise用户定义的工厂:
FactoryGirl.define do
factory :user do
email 'test@example.com'
password 'foobar'
password_confirmation 'foobar'
end
end
Run Code Online (Sandbox Code Playgroud)
这是spec_helper.rb:
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'email_spec'
require 'rspec/autorun'
require 'factory_girl'
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
RSpec.configure do |config|
config.include(EmailSpec::Helpers)
config.include(EmailSpec::Matchers)
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = false
config.order = "random"
config.include Devise::TestHelpers, :type => :controller
config.include FactoryGirl::Syntax::Methods
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end …Run Code Online (Sandbox Code Playgroud)