Better speccing
This commit is contained in:
@@ -1,48 +1,57 @@
|
|||||||
module Admin
|
module Admin
|
||||||
class UsersController < Admin::ApplicationController
|
class UsersController < Admin::ApplicationController
|
||||||
|
skip_before_filter :authenticate_administrator!, only: :test_login
|
||||||
# GET /users
|
# GET /users
|
||||||
# GET /users.json
|
# GET /users.json
|
||||||
def index
|
def index
|
||||||
@users = User.all
|
@users = User.all
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # index.html.erb
|
format.html # index.html.erb
|
||||||
format.json { render json: @users }
|
format.json { render json: @users }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /users/1
|
# GET /users/1
|
||||||
# GET /users/1.json
|
# GET /users/1.json
|
||||||
def show
|
def show
|
||||||
@user = User.find(params[:id])
|
@user = User.find(params[:id])
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # show.html.erb
|
format.html # show.html.erb
|
||||||
format.json { render json: @user }
|
format.json { render json: @user }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def test_login
|
||||||
|
if Rails.env.test? and user = User.find_by_email(params[:email])
|
||||||
|
sign_in user
|
||||||
|
end
|
||||||
|
render nothing: true
|
||||||
|
end
|
||||||
|
|
||||||
# GET /users/new
|
# GET /users/new
|
||||||
# GET /users/new.json
|
# GET /users/new.json
|
||||||
def new
|
def new
|
||||||
@user = User.new
|
@user = User.new
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # new.html.erb
|
format.html # new.html.erb
|
||||||
format.json { render json: @user }
|
format.json { render json: @user }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /users/1/edit
|
# GET /users/1/edit
|
||||||
def edit
|
def edit
|
||||||
@user = User.find(params[:id])
|
@user = User.find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
# POST /users
|
# POST /users
|
||||||
# POST /users.json
|
# POST /users.json
|
||||||
def create
|
def create
|
||||||
@user = User.new(params[:user])
|
@user = User.new(params[:user])
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @user.save
|
if @user.save
|
||||||
format.html { redirect_to [:admin, @user], notice: t('action.create.successfull', model: User.model_name.human) }
|
format.html { redirect_to [:admin, @user], notice: t('action.create.successfull', model: User.model_name.human) }
|
||||||
@@ -53,12 +62,12 @@ module Admin
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# PUT /users/1
|
# PUT /users/1
|
||||||
# PUT /users/1.json
|
# PUT /users/1.json
|
||||||
def update
|
def update
|
||||||
@user = User.find(params[:id])
|
@user = User.find(params[:id])
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @user.update_attributes(params[:user])
|
if @user.update_attributes(params[:user])
|
||||||
format.html { redirect_to [:admin, @user], notice: t('action.update.successfull', model: User.model_name.human) }
|
format.html { redirect_to [:admin, @user], notice: t('action.update.successfull', model: User.model_name.human) }
|
||||||
@@ -69,13 +78,13 @@ module Admin
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# DELETE /users/1
|
# DELETE /users/1
|
||||||
# DELETE /users/1.json
|
# DELETE /users/1.json
|
||||||
def destroy
|
def destroy
|
||||||
@user = User.find(params[:id])
|
@user = User.find(params[:id])
|
||||||
@user.destroy
|
@user.destroy
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to admin_users_url, notice: t('action.destroy.successfull', model: User.model_name.human) }
|
format.html { redirect_to admin_users_url, notice: t('action.destroy.successfull', model: User.model_name.human) }
|
||||||
format.json { head :no_content }
|
format.json { head :no_content }
|
||||||
|
|||||||
+5
-1
@@ -3,7 +3,11 @@ Qwaiter::Application.routes.draw do
|
|||||||
devise_for :suppliers, controllers: { confirmations: 'confirmations' }
|
devise_for :suppliers, controllers: { confirmations: 'confirmations' }
|
||||||
devise_for :administrators
|
devise_for :administrators
|
||||||
namespace :admin do
|
namespace :admin do
|
||||||
resources :users
|
resources :users do
|
||||||
|
collection do
|
||||||
|
get :test_login
|
||||||
|
end
|
||||||
|
end
|
||||||
resources :suppliers
|
resources :suppliers
|
||||||
resources :tables
|
resources :tables
|
||||||
resources :orders
|
resources :orders
|
||||||
|
|||||||
@@ -4,13 +4,15 @@ Feature: Sign up as user using facebook
|
|||||||
Scenario: Happy flow
|
Scenario: Happy flow
|
||||||
Given There is no user information stored in the local storage
|
Given There is no user information stored in the local storage
|
||||||
When I visit the user obtain token path
|
When I visit the user obtain token path
|
||||||
Then I should be signed in as a user
|
Then I should be signed in as a user through facebook
|
||||||
|
And I wait 4 seconds
|
||||||
And I should be redirected to the user home
|
And I should be redirected to the user home
|
||||||
And the newly created user info should be stored in the local storage
|
And the newly created user info should be stored in the local storage
|
||||||
|
|
||||||
@broken
|
@javascript
|
||||||
Scenario: Already signed in user visits obtain token path
|
Scenario: Already signed in user visits obtain token path
|
||||||
Given I am signed in as a user
|
Given I am signed in as a user
|
||||||
And There is no user information stored in the local storage
|
When I visit '/user'
|
||||||
|
And I wait 4 seconds
|
||||||
Then I should be redirected to the user home
|
Then I should be redirected to the user home
|
||||||
And the newly created user info should be stored in the local storage
|
And the newly created user info should be stored in the local storage
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ step "I click on translation :translation" do |translation_key|
|
|||||||
click_on text
|
click_on text
|
||||||
end
|
end
|
||||||
|
|
||||||
|
step 'I visit :path' do |path|
|
||||||
|
visit path
|
||||||
|
end
|
||||||
|
|
||||||
step "I wait :number second/seconds" do |number|
|
step "I wait :number second/seconds" do |number|
|
||||||
sleep number.to_f
|
sleep number.to_f
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,22 +1,29 @@
|
|||||||
|
|
||||||
step "There is no user information stored in the local storage" do
|
step "There is no user information stored in the local storage" do
|
||||||
|
page.evaluate_script(%|Qstorage.getItem('user_id')|).should be_blank
|
||||||
|
page.evaluate_script(%|Qstorage.getItem('auth_token')|).should be_blank
|
||||||
end
|
end
|
||||||
|
|
||||||
step "I visit the user obtain token path" do
|
step "I visit the user obtain token path" do
|
||||||
visit user_obtain_token_path
|
visit user_obtain_token_path
|
||||||
end
|
end
|
||||||
|
|
||||||
step "I should be signed in as a user" do
|
step "I am signed in as a user" do
|
||||||
|
@user ||= create :user
|
||||||
|
visit test_login_admin_users_path(email: @user.email)
|
||||||
|
end
|
||||||
|
|
||||||
|
step "I should be signed in as a user through facebook" do
|
||||||
@user = User.find_by_oauth_token 'fbAuthToken234'
|
@user = User.find_by_oauth_token 'fbAuthToken234'
|
||||||
page.evaluate_script(%|Qstorage.getItem('user_id')|).should == @user.id
|
# For now, actually better to test a signed in response from the server
|
||||||
page.evaluate_script(%|Qstorage.getItem('auth_token')|).should == @user.authentication_token
|
step "the newly created user info should be stored in the local storage"
|
||||||
binding.pry
|
|
||||||
end
|
end
|
||||||
|
|
||||||
step "I should be redirected to the user home" do
|
step "I should be redirected to the user home" do
|
||||||
|
page.current_path.should == user_root_path
|
||||||
end
|
end
|
||||||
|
|
||||||
step "the newly created user info should be stored in the local storage" do
|
step "the newly created user info should be stored in the local storage" do
|
||||||
|
page.evaluate_script(%|Qstorage.getItem('user_id')|).should == @user.id
|
||||||
|
page.evaluate_script(%|Qstorage.getItem('auth_token')|).should == @user.authentication_token
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user