Skip to content

Instantly share code, notes, and snippets.

@AttyC
Created September 8, 2015 12:34
Show Gist options
  • Save AttyC/7181d499de011a119777 to your computer and use it in GitHub Desktop.
Save AttyC/7181d499de011a119777 to your computer and use it in GitHub Desktop.
Functional tests User Controller
require 'rails_helper'
describe StaticPagesController, :type => :controller do
describe "GET #index" do
it "responds successfully with an HTTP 200 status code" do
get :index
expect(response).to be_success
expect(response).to have_http_status(200)
end
it "renders the index template" do
get :index
expect(response).to render_template("index")
end
end
describe "GET #landing_page" do
it "responds successfully with an HTTP 200 status code" do
get :landing_page
expect(response).to be_success
expect(response).to have_http_status(200)
end
it "renders the landing_page template" do
get :landing_page
expect(response).to render_template("landing_page")
end
end
describe "GET #featured_page" do
it "responds successfully with an HTTP 200 status code" do
get :featured_page
expect(response).to be_success
expect(response).to have_http_status(200)
end
it "renders the featured_page template" do
get :featured_page
expect(response).to render_template("featured_page")
end
end
describe "GET #about" do
it "responds successfully with an HTTP 200 status code" do
get :about
expect(response).to be_success
expect(response).to have_http_status(200)
end
it "renders the about template" do
get :about
expect(response).to render_template("about")
end
end
describe "GET #contact" do
it "responds successfully with an HTTP 200 status code" do
get :contact
expect(response).to be_success
expect(response).to have_http_status(200)
end
it "renders the contact template" do
get :contact
expect(response).to render_template("contact")
end
end
end
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_many :orders
end
class UsersController < ApplicationController
before_action :set_user, only: [:show, :edit, :update, :destroy]
load_and_authorize_resource
# GET /users
# GET /users.json
def index
@users = User.all
end
# GET /users/1
# GET /users/1.json
def show
end
# GET /users/new
def new
@user = User.new
end
# GET /users/1/edit
def edit
end
# POST /users
# POST /users.json
def create
@user = User.new(user_params)
respond_to do |format|
if @user.save
format.html { redirect_to @user, notice: 'User was successfully created.' }
format.json { render :show, status: :created, location: @user }
else
format.html { render :new }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /users/1
# PATCH/PUT /users/1.json
def update
respond_to do |format|
if @user.update(user_params)
format.html { redirect_to @user, notice: 'User was successfully updated.' }
format.json { render :show, status: :ok, location: @user }
else
format.html { render :edit }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
# DELETE /users/1
# DELETE /users/1.json
def destroy
@user.destroy
respond_to do |format|
format.html { redirect_to users_url, notice: 'User was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_user
@user = User.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def user_params
params.require(:user).permit(:first_name, :last_name, :email, :password, :encrypted_password)
end
end
require 'rails_helper'
describe UsersController, :type => :controller do
describe "GET #index" do
before do
@user = User.create!(:email => "[email protected]", :password => "12345678")
end
it "responds successfully with an HTTP 200 status code" do
get :index
expect(response).to be_success
expect(response).to have_http_status(200)
end
it "renders the index template" do
get :index
expect(response).to render_template("index")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment