我试图在我的测试代码中使用reset_session,但它抱怨找不到任何方法.我也尝试使用我在测试中编写的一些身份验证方法,它们也没有产生方法错误(它们在我的application_controller中)
有人可以帮忙解释一下
a)这是所有人都遇到的问题,而不仅仅是我b)解决方法
***编辑 - 继承人一些代码********
来自我的app控制器
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
protect_from_forgery # See ActionController::RequestForgeryProtection for details
include SpreedyTools
# Scrub sensitive parameters from your log
# filter_parameter_logging :password
protected
def logged_in_user?
@logged_in_user = User.find(session[:user]) if session[:user]
end
def logged_in_user=user
if !user.nil?
session[:user] = user
@logged_in_user = user
end
end
def logged_in_user
if logged_in_user?
return @logged_in_user
end
end
#checks to see if there is a user logged in, if not redirects …Run Code Online (Sandbox Code Playgroud) 鉴于这个例子:
class Server < ActiveRecord::Base
has_many :clients,:dependent => :destroy
after_destroy: delete_server_directory
end
class Client < ActiveRecord::Base
belongs_to :server
before_destroy :copy_some_important_stuff_from_the_server_directory_before_its_too_late
end
Run Code Online (Sandbox Code Playgroud)
当我打电话时,这会是毁灭的顺序server.destroy吗?
Server#clients,伴随着Client的before/after_destroy回调Server 将被销毁Server是after_destroy回调提案文档可以分为许多不同的部分类型(文本,费用,时间表)等
这里使用连接表上的多态关联建模.
class Proposal < ActiveRecord::Base
has_many :proposal_sections
has_many :fee_summaries, :through => :proposal_sections, :source => :section, :source_type => 'FeeSummary'
end
class ProposalSection < ActiveRecord::Base
belongs_to :proposal
belongs_to :section, :polymorphic => true
end
class FeeSummary < ActiveRecord::Base
has_many :proposal_sections, :as => :section
has_many :proposals, :through => :proposal_sections
end
Run Code Online (Sandbox Code Playgroud)
虽然#create工作正常
summary = @proposal.fee_summaries.create
summary.proposal == @propsal # true
Run Code Online (Sandbox Code Playgroud)
#new不要
summary = @proposal.fee_summaries.new
summary.proposal -> nil
Run Code Online (Sandbox Code Playgroud)
它应该返回零吗?
在常规的has_many和belongs_to初始化但尚未存在的记录仍将返回其父关联(内置在内存中).
为什么这不起作用,是否是预期的行为?
Schema.rb
create_table "fee_summaries", :force => true do |t|
t.datetime "created_at", :null => false
t.datetime …Run Code Online (Sandbox Code Playgroud) 我每天都在从网站上收集数据.每天我都运行scrapy,第一个请求总是被重定向到网站主页,因为看起来scrapy还没有设置任何cookie.但是在第一次请求之后,scrapy会收到cookie,从那时起就可以了.
然而,这使我很难使用"scrapy view"等工具与任何特定网址,因为网站将始终重定向到主页,这就是我的浏览器将打开scrapy.
可以scrapy保存cookie,我指定在所有擦除上使用它吗?我可以指定使用它与scrapy视图等.
由于本地计算机的空间限制,我需要确保我的 Docker 容器将其数据存储在我的外部硬盘驱动器上。
我正在使用的 docker 项目有一个 docker compose 文件,它指定了多个卷,如下所示:
version: "2"
volumes:
pgdata:
cache:
services:
postgres:
image: "openmaptiles/postgis:${TOOLS_VERSION}"
volumes:
- pgdata:/var/lib/postgresql/data
Run Code Online (Sandbox Code Playgroud)
这些卷最终存在于我的本地计算机上。我想将它们的位置更改为我的外部驱动器上的某个位置,例如 /Volumes/ExternalDrive/docker/
我该怎么办?
我已阅读有关卷和docker-compose的 docker 文档,但找不到指定卷应存在的路径的方法。
如果有人能指点迷津,我将不胜感激。
我曾经在rails blogs上看到卷曲的提及,我已经在stackoverflow上扫描了一些帖子,但我仍然有点在黑暗中使用它,特别是在涉及rails开发时.
它对测试有用吗?我目前正在学习测试的细节,我需要做的一件事是测试一个过滤器,它只允许在用户来自某个外部站点时调用一个动作.这是卷曲使用的场合吗?
我正在使用一个Twitter宝石,基本上访问Twitter,让我抓住推文,时间线等.它真的很好,但我有很多我的代码使用它返回的东西,我需要测试它.宝石返回的东西不是简单的字符串,有非常复杂的对象(也很可怕),所以我留下了挠头.
所以基本上我正在寻找一个答案,书籍,博客,开源项目,它可以向我展示围绕外部服务进行测试的权利和错误.
最重要的是,不是以语言为中心或以ruby/rails为中心的答案.
我有3种型号:
User
has_many :questions
has_many :corrections
end
Question
has_one :correction
belongs_to :user
end
Correction
belongs_to :user
belongs_to :question
Run Code Online (Sandbox Code Playgroud)
因此,如果用户Bob提出问题,则用户Terry可以检查该问题,以及是否有错误提供了更正。
让我们呆在鲍勃身边,并假设他已善意地纠正了5个其他用户,即,并假设他很幸运地从其他用户那里获得了3次更正。
我希望能够做这样的事情
@ bob.corrections_offered => 5个校正对象@ bob.corrections_received => 3个校正对象
第一个很容易,因为它实际上是@ bob.corrections。但是我不知道如何实现后者。有人可以帮忙吗?
更新
因此,我尝试按照建议的方式使用直通车(哦,实际上,上面的问题模型在我的代码中实际上称为Sentence。即User => Sentence => Correction。)
has_many :sentences
has_many :corrections_received, :through => :sentences, :class_name => 'Correction'
Run Code Online (Sandbox Code Playgroud)
但是在控制台中出现此错误
ActiveRecord :: HasManyThroughSourceAssociationNotFoundError:在模型语句中找不到源关联:纠正。尝试'has_many:corrections_received,:through =>:sentences,:source =>'。是:language,:correction,:user或:checker之一?
所以尝试了以下
has_many :corrections_received, :through => :sentences, :source => :correction
Run Code Online (Sandbox Code Playgroud)
但是得到了
ActiveRecord :: HasManyThroughSourceAssociationMacroError:无效的源反射宏:has_one for has_many:corrections_received,:through =>:sentences。使用:source指定源反射。
不知道出了什么问题...
尽管遵循了文档,我仍然得到以下错误.
在test_helper.rb中
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require "authlogic/test_case"
require 'test_help'
require 'shoulda'
require File.dirname(__FILE__) + "/factories"
Run Code Online (Sandbox Code Playgroud)
在我的功能测试中需要'test_helper'
class SentencesControllerTest < ActionController::TestCase
setup do
:activate_authlogic
end
context "logged in" do
setup do
@user = Factory(:user)
UserSession.create(@user.id)
end
context "on GET to :new" do
setup do
get :new
end
should "present form with text field" do
assert_select('form#new_sentence') do
assert_select('textarea#sentence_text')
end
end
end
end #context logged in.
end
Run Code Online (Sandbox Code Playgroud)
在environments.rb中
config.gem "authlogic"
Run Code Online (Sandbox Code Playgroud)
我不知道为什么它不起作用.任何人都可以帮忙吗?
Authlogic::Session::Activation::NotActivatedError: You must activate the Authlogic::Session::Base.controller with a …Run Code Online (Sandbox Code Playgroud) 我喜欢使用irb快速检查我的ruby代码如何反应.我想知道有没有办法在Firebug或soem其他工具中做同样的事情?