我生成了带有帖子资源的脚手架应用程序。
以下是测试代码
describe "GET index" do
it "assigns all posts as @posts" do
post = Post.create! valid_attributes
get :index, {}, valid_session
assigns(:posts).should eq([post])
end
end
下面是posts#index的实现
# GET /posts
# GET /posts.json
de
在商店模式中:
class Shop < ActiveRecord::Base
alias_attribute :token, :basic_token
# basic_token column is set NOT to be NULL in DB
end
在商店工厂:
FactoryGirl.define do
factory :shop do
basic_token '12313123123123123123123'
...
...
end
end
在RSPEC商店主计长:
require 'rails_helper&
我测试.,这个索引动作‘填充一个数组的所有问题。
require 'rails_helper'
RSpec.describe QuestionsController, type: :controller do
describe 'GET #index' do
before do
@questions = FactoryGirl.create_list(:question, 2)
get :index
end
it 'populates an array of all questions'
我正在尝试使用BDD和RSpec来创建一个Rails的应用编程接口。Rails版本是3.1.1,Ruby版本是1.9.2,Devise版本是1.5.3,rspec版本是2.7.0。我是Rails的新手,也是RSpec的新手。
我定义了一个简单的RSpec,如下所示,用来测试基本上没有逻辑的FormsController。
describe FormsController, " handling GET /forms" do
include Devise::TestHelpers
render_views
before do
user = F
我有一个表,我计划从CSV文件中填充。该文件包括22列,表包括24列。不同之处是列列表末尾的created_at和updated_at字段。
我真正想要发生的是,每一条记录都要被创建,最后2列是默认的。
我添加了这样的列:
ALTER TABLE mytable
ADD created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
ADD updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
;
我的加载程序脚本如下所示:
LOAD DATA LOCAL IN
对于GET请求,我有一个失败的测试--问题在于ActiveRecord的时间戳在响应中的格式化方式。RSpec测试期望数据格式为Mon, 29 Dec 2014 13:37:09 UTC +00:00,,但它却接收2014-12-29T13:37:09Z。是否有任何方法来更改ActiveRecord时间戳的格式,或者RSpec测试所期望的?
编辑:
下面是失败的测试:
describe 'GET /v1/tasks/:id' do
it 'returns an task by :id' do
task = create(:task)
get
这件事困扰了我一段时间了..。
如何在Rails datetime查询中插入ActiveRecord字符串?
# Works, but supeh ugleh:
Model.where("created_at >= ?", Time.now - 5.days)
# How do I do this?
Model.where("created_at >= #{Time.now - 5.days}")
# As is, it produces the following error message:
# ActiveRecord::StatementI
我正在使用Phoenix Framework将Rails中编写的API重写为Elixir。
主网站使用Rails,并将继续使用Rails。但是,我希望API使用Elixir。
我需要能够从我的Elixir API项目中读取created_at字段。
defmodule Example.Recipe do
use Ecto.Schema
schema "recipes" do
field :name, :string
field :description, :string
field :slug, :string
field :creat