- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我似乎左右都遇到了失败...我检查了我的代码,一切都已定义并且拼写检查正在检查...这是我的失败...:
Failures:
1) User pages index should list each user
Failure/Error: visit users_path
ActionView::Template::Error:
wrong number of arguments (2 for 1)
# ./app/helpers/users_helper.rb:4:in `gravatar_for'
# ./app/views/users/index.html.erb:7:in `block in _app_views_users_index_html_erb___3453469340594189774_70210782785680'
# ./app/views/users/index.html.erb:5:in `each'
# ./app/views/users/index.html.erb:5:in `_app_views_users_index_html_erb___3453469340594189774_70210782785680'
# ./spec/requests/user_pages_spec.rb:12:in `block (3 levels) in <top (required)>'
2) User pages index
Failure/Error: visit users_path
ActionView::Template::Error:
wrong number of arguments (2 for 1)
# ./app/helpers/users_helper.rb:4:in `gravatar_for'
# ./app/views/users/index.html.erb:7:in `block in _app_views_users_index_html_erb___3453469340594189774_70210782785680'
# ./app/views/users/index.html.erb:5:in `each'
# ./app/views/users/index.html.erb:5:in `_app_views_users_index_html_erb___3453469340594189774_70210782785680'
# ./spec/requests/user_pages_spec.rb:12:in `block (3 levels) in <top (required)>'
3) User pages index
Failure/Error: visit users_path
ActionView::Template::Error:
wrong number of arguments (2 for 1)
# ./app/helpers/users_helper.rb:4:in `gravatar_for'
# ./app/views/users/index.html.erb:7:in `block in _app_views_users_index_html_erb___3453469340594189774_70210782785680'
# ./app/views/users/index.html.erb:5:in `each'
# ./app/views/users/index.html.erb:5:in `_app_views_users_index_html_erb___3453469340594189774_70210782785680'
# ./spec/requests/user_pages_spec.rb:12:in `block (3 levels) in <top (required)>'
Finished in 1.87 seconds
70 examples, 3 failures
Failed examples:
rspec ./spec/requests/user_pages_spec.rb:18 # User pages index should list each user
rspec ./spec/requests/user_pages_spec.rb:16 # User pages index
rspec ./spec/requests/user_pages_spec.rb:15 # User pages index
这是我的代码:规范/请求/user_pages_spec.rb
require 'spec_helper'
describe "User pages" do
subject { page }
describe "index" do
before do
sign_in FactoryGirl.create(:user)
FactoryGirl.create(:user, name: "Bob", email: "bob@example.com")
FactoryGirl.create(:user, name: "Ben", email: "ben@example.com")
visit users_path
end
it { should have_selector('title', text: 'All users') }
it { should have_selector('h1', text: 'All users') }
it "should list each user" do
User.all.each do |user|
page.should have_selector('li', text: user.name)
end
end
end
describe "profile page" do
let(:user) { FactoryGirl.create(:user) }
before { visit user_path(user) }
it { should have_selector('h1', text: user.name) }
it { should have_selector('title', text: user.name) }
end
describe "signup page" do
before { visit signup_path }
it { should have_selector('h1', text: 'Sign up') }
it { should have_selector('title', text: full_title('Sign up')) }
end
describe "signup" do
before { visit signup_path }
let(:submit) { "Create my account" }
describe "with invalid information" do
it "should not create a user" do
expect { click_button submit }.not_to change(User, :count)
end
end
describe "with valid information" do
before do
fill_in "Name", with: "Example User"
fill_in "Email", with: "user@example.com"
fill_in "Password", with: "foobar"
fill_in "Confirmation", with: "foobar"
end
describe "after saving the user" do
before { click_button submit }
let(:user) { User.find_by_email('user@example.com') }
it { should have_selector('title', text: user.name) }
it { should have_selector('div.alert.alert-success', text: 'Welcome') }
it { should have_link('Sign out') }
end
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
end
end
describe "edit" do
let(:user) { FactoryGirl.create(:user) }
before do
sign_in user
visit edit_user_path(user)
end
describe "page" do
it { should have_selector('h1', text: "Update your profile") }
it { should have_selector('title', text: "Edit user") }
it { should have_link('change', href: 'http://gravatar.com/emails') }
end
describe "with invalid information" do
before { click_button "Save changes" }
it { should have_content('error') }
end
describe "with valid information" do
let(:new_name) { "New Name" }
let(:new_email) { "new@example.com" }
before do
fill_in "Name", with: new_name
fill_in "Email", with: new_email
fill_in "Password", with: user.password
fill_in "Confirm Password", with: user.password
click_button "Save changes"
end
it { should have_selector('title', text: new_name) }
it { should have_selector('div.alert.alert-success') }
it { should have_link('Sign out', href: signout_path) }
specify { user.reload.name.should == new_name }
specify { user.reload.email.should == new_email }
end
end
end
用户 Controller .rb
class UsersController < ApplicationController
before_filter :signed_in_user, only: [ :index, :edit, :update]
before_filter :correct_user, only: [:edit, :update]
def show
@user = User.find(params[:id])
end
def new
@user = User.new
end
def create
@user = User.new(params[:user])
if @user.save
sign_in @user
flash[:success] = "Welcome to the Sample App!"
redirect_to @user
else
render 'new'
end
end
def index
@users = User.all
end
def edit
end
def update
if @user.update_attributes(params[:user])
flash[:success] = "Profile updated"
sign_in @user
redirect_to @user
else
render 'edit'
end
end
private
def signed_in_user
unless signed_in?
store_location
redirect_to signin_url, notice: "Please sign in."
end
end
def correct_user
@user = User.find(params[:id])
redirect_to(root_path) unless current_user?(@user)
end
end
index.html.erb:
<% provide(:title, 'All users') %>
<h1>All users</h1>
<ul class="users">
<% @users.each do |user| %>
<li>
<%= gravatar_for user, size: 52 %>
<%= link_to user.name, user %>
</li>
<% end %>
</ul>
authentication_pages_spec.rb
require 'spec_helper'
describe "Authentication" do
subject { page }
describe "signin page" do
before { visit signin_path }
it { should have_selector('h1', text: 'Sign in') }
it { should have_selector('title', text: 'Sign in') }
end
describe "signin" do
before { visit signin_path }
describe "with invalid information" do
before { click_button "Sign in" }
it { should have_selector('title', text: 'Sign in') }
it { should have_selector('div.alert.alert-error', text: 'Invalid') }
describe "after visiting another page" do
before { click_link "Home" }
it { should_not have_selector('div.alert.alert-error') }
end
end
describe "with valid information" do
let(:user) { FactoryGirl.create(:user) }
before { sign_in user }
it { should have_selector('title', text: user.name) }
it { should have_link('Users', href: users_path) }
it { should have_link('Profile', href: user_path(user)) }
it { should have_link('Settings', href: edit_user_path(user)) }
it { should have_link('Sign out', href: signout_path) }
it { should_not have_link('Sign in', href: signin_path) }
describe "followed by signout" do
before { click_link "Sign out" }
it { should have_link('Sign in') }
end
end
end
describe "authorization" do
describe "for non-signed-in users" do
let(:user) { FactoryGirl.create(:user) }
describe "in the Users controller" do
describe "visiting the edit page" do
before { visit edit_user_path(user) }
it { should have_selector('title', text: 'Sign in') }
end
describe "submitting to the update action" do
before { put user_path(user) }
specify { response.should redirect_to(signin_path) }
end
describe "visiting the user index" do
before { visit users_path }
it { should have_selector('title', text: 'Sign in') }
end
end
describe "when attempting to visit a protected page" do
before do
visit edit_user_path(user)
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
end
describe "after signing in" do
it "should render the desired protected page" do
page.should have_selector('title', text: 'Edit user')
end
end
end
end
describe "as wrong user" do
let(:user) { FactoryGirl.create(:user) }
let(:wrong_user) { FactoryGirl.create(:user, email: "wrong@example.com") }
before { sign_in user }
describe "visiting Users#edit page" do
before { visit edit_user_path(wrong_user) }
it { should_not have_selector('title', text: full_title('Edit user')) }
end
describe "submitting a PUT request to the Users#update action" do
before { put user_path(wrong_user) }
specify { response.should redirect_to(root_path) }
end
end
end
end
sussions_helper.rb
module SessionsHelper
def sign_in(user)
cookies.permanent[:remember_token] = user.remember_token
self.current_user = user
end
def signed_in?
!current_user.nil?
end
def current_user=(user)
@current_user = user
end
def current_user
@current_user ||= User.find_by_remember_token(cookies[:remember_token])
end
def current_user?(user)
user == current_user
end
def sign_out
self.current_user = nil
cookies.delete(:remember_token)
end
def redirect_back_or(default)
redirect_to(session[:return_to] || default)
session.delete(:return_to)
end
def store_location
session[:return_to] = request.url
end
end
session Controller .rb
class SessionsController < ApplicationController
def new
end
def create
user = User.find_by_email(params[:session][:email].downcase)
if user && user.authenticate(params[:session][:password])
sign_in user
redirect_back_or user
else
flash.now[:error] = 'Invalid email/password combination'
render 'new'
end
end
def destroy
sign_out
redirect_to root_url
end
end
这里有什么问题??有什么建议吗?
最佳答案
您需要代码 list 7.29 中的代码。用于编辑头像。
Listing 7.29. Defining an optional :size parameter for the gravatar_for helper.
app/helpers/users_helper.rb
module UsersHelper
# Returns the Gravatar (http://gravatar.com/) for the given user.
def gravatar_for(user, options = { size: 50 })
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
size = options[:size]
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}"
image_tag(gravatar_url, alt: user.name, class: "gravatar")
end
end
关于testing - Hartl RoR Chap。 9.3.1 规范测试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14916144/
我已经使用 RailsInstaller 安装了 Ruby on Rails,还在 Windows 8 中安装了 postgresql。我正在尝试使用文件运行 rails server,但我收到错误消
我正在尝试关注 Ryan Bates RailsCast #196: Nested model form part 1 。 Ryans 版本有两个明显的区别:1)我使用的是内置脚手架,不像他使用的那么
你好,我通过内部连接获取了重复的数据行。我编写了带有 OR 条件的内部连接。 Controller userscontroller.rb @users = User.search(params[:se
我已经创建了一个表,现在我想给表添加一个关联(has_many 关系)。如果我已经创建了一个表并且在创建模型后已经完成了 rake db:migrate,我该怎么办? 在ror中创建表后是否可以添加关
我正在尝试将数据插入 ROR 中的数据库,对于电话号码,我采用了字段整数..但它只采用了 9 位数字..如果我尝试输入 10 位数字。它提供错误作为。 Mysql2::Error: Out of ra
如何获得事件项目菜单?循环生成菜单 我想为这个项目使用其他 css 属性。有任何想法吗?最好是js,jquery... 最佳答案 link_to_unless_
我正在编辑设计生成的用户模型,为用户添加一个语言字段,他可以在其中添加他从组合框中所说的一种或多种语言。 我的问题是在 mysql 中表示这一点的最佳方式是什么。我不知道他会说多少种语言,所以可能最多
我对 Rails 很陌生,并且对这个问题的逻辑有点困惑。 我有一张员工表(使用mysql),每个员工都有一个manager_id键,该键指的是他们向其汇报的员工。例如,标题为“CEO”且 id 为 1
那里的例子很少,但没有一个是非常清楚的(或在旧版本上)。 我想调用 MySQL 过程并检查返回状态(在 rails 4.2 中)。我看到的最常见的方法是调用 result = ActiveRecord
我在 /public 下有一些静态错误页面,我在其中按以下方式链接了一个名为 errors.min.css 的样式表: 但是,当我在除根路径 (/abc/non-existent-url) 之外的路
我想在 RoR 中将一张图片叠加在另一张图片上。 在纯 html 中这样做很容易(来自 https://stackoverflow.com/a/1997397/1760830 ): 当
我正在努力将静态站点引入 ruby on rails 应用程序,以便我们可以构建功能等。 我已经使用页面 Controller 设置了所有静态页面,并将所有静态页面存储在 View /页面下...
我在表格中有一个单元格,看起来像 我想编写一个 CSS 类,根据 play_result.status 的值更改此单元格的字体颜色,绿色代表字符串“OK”,橙色代表“CHANGED”,蓝色代表“
我正在尝试绑定(bind)帖子搜索页面上的类别下拉列表。下拉菜单应将类别图像显示为下拉菜单中类别名称左侧的图标。 下一行绑定(bind)所有类别并在下拉列表中显示它们的名称: 'Any') %> 我
在 Ruby 代码的 TextField 中,我想在模糊事件中检查指定的类是否被应用。请建议一些技术或方法。下面给出了我使用的示例代码。 TextField 的 Ruby 代码:: 4, :t
试图弄清楚 Ruby On Rails 中如何处理并发。 如何获取一段代码来锁定数据库中的行并在需要时强制回滚? 更具体地说,有没有办法强制某一段代码完全完成,如果不回滚?我想在我的项目中为交易添加历
我们正在开发一个 Rails 应用程序,其中一类用户可以编辑和创建文章。有时这些文章包含指向网站上其他文章的链接。执行以下操作的最佳方法是什么? 将链接存储在数据库中 在页面上呈现链接 目前我们有绑定
我有以下 ROR 代码 def func (point,c,r) res=isPointInCircle(point,c,r) #returns true/ false if
如何在 Rails 3.0 中使用 MD5 加密字符串?模型中的 pass = MD5.hexdigest(pass) 产生 未初始化的常量 MyModel::MD5 最佳答案 为此,您可以使用 Ru
我正在寻找有关监控每天大约有 250,000 次插入的特定表的建议。规模不大,但增长迅速,我们不能像现在这样继续工作。 主要应用程序依赖于带有 MySQL 数据库的 RoR4。数据从多个 Radius
我是一名优秀的程序员,十分优秀!