(непротестированный) что-то вроде этого может сделать задание
WITH
base AS
(
select * -- get the table
from sometable
order by name -- in the desired order
),
twenty AS
(
select * -- get the first 30 rows
from base
where rownum < 30
order by name -- in the desired order
)
select * -- then get rows 21 .. 30
from twenty
where rownum > 20
order by name -- in the desired order
существует также разряд аналитической функции, который можно использовать для упорядочивания.
На основе кода в методе user_sessions_controller
create
, который принимает хэш учетных данных для входа, я смог заставить его работать таким образом в моей интеграции test:
UserSession.create(:email => 'someone@example.com', :password => 'password')
, но не с:
UserSession.create(@user)
Я обнаружил, что для интеграционных тестов мне нужно войти в систему через сообщение:
setup do
post 'user_session', :user_session => {:email => 'someone@example.com', :password => 'password'}
end
Это устанавливает сеанс правильно, в то время как упомянутый выше метод работает у меня только в функциональных тестах.
I'm also using Authlogic with Shoulda (but with factory_girl on top).
My functionnal tests look like :
require 'test_helper'
class LoansControllerTest < ActionController::TestCase
[...]
context "as a signed-in user, with an active loan" do
setup do
@user = Factory(:user)
@user_session = UserSession.create(@user)
@loan = Factory(:loan, :ownership => Factory(:ownership, :user => @user))
end
context "on GET to :index" do
setup do
get :index
end
should_respond_with_success
end
end
end
Actually, you CAN pass a valid user to UserSession, it's in the rdoc also. You should also avoid calling activate_authlogic in each controller test :
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
class ActiveSupport::TestCase
[...]
# Add more helper methods to be used by all tests here...
include Authlogic::TestCase
def setup
activate_authlogic
end
end
Yeah, I found this week that with rspec: in functional specs you simulate log in just fine w/ UserSession.create(@user)
. But if you try that in an integration spec it doesn't work. In order to log in from integration specs I found I had to drive the forms (with webrat) which clearly will be a problem for things like Facebook and OpenID log in.