forked from External/greenlight
add controller tests
This commit is contained in:
parent
7c6174edc5
commit
df90f4aade
|
@ -0,0 +1,25 @@
|
|||
require "rails_helper"
|
||||
|
||||
describe ErrorsController, type: :controller do
|
||||
|
||||
describe "GET #not_found" do
|
||||
it "returns not_found" do
|
||||
get :not_found
|
||||
expect(response).to have_http_status(404)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #unprocessable" do
|
||||
it "returns unprocessable" do
|
||||
get :unprocessable
|
||||
expect(response).to have_http_status(422)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET #internal_error" do
|
||||
it "returns internal_error" do
|
||||
get :internal_error
|
||||
expect(response).to have_http_status(500)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
require "rails_helper"
|
||||
|
||||
describe MainController, type: :controller do
|
||||
|
||||
describe "GET #index" do
|
||||
it "returns success" do
|
||||
get :index
|
||||
expect(response).to be_successful
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,88 @@
|
|||
require "rails_helper"
|
||||
|
||||
describe UsersController, type: :controller do
|
||||
|
||||
let(:user_params) {
|
||||
{
|
||||
user: {
|
||||
name: "Example",
|
||||
email: "example@example.com",
|
||||
password: "password",
|
||||
password_confirmation: "password"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let(:invalid_params) {
|
||||
{
|
||||
user: {
|
||||
name: "Invalid",
|
||||
email: "example.com",
|
||||
password: "pass",
|
||||
password_confirmation: "invalid"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
describe "GET #new" do
|
||||
it "assigns a blank user to the view" do
|
||||
get :new
|
||||
expect(assigns(:user)).to be_a_new(User)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST #create" do
|
||||
it "redirects to user room on succesful create" do
|
||||
post :create, params: user_params
|
||||
|
||||
u = User.last
|
||||
expect(u).to_not be_nil
|
||||
expect(u.name).to eql("Example")
|
||||
expect(response).to redirect_to(room_path(u.main_room))
|
||||
end
|
||||
|
||||
it "redirects to main room if already authenticated" do
|
||||
user = create(:user)
|
||||
@request.session[:user_id] = user.id
|
||||
|
||||
post :create, params: user_params
|
||||
expect(response).to redirect_to(room_path(user.main_room))
|
||||
end
|
||||
|
||||
it "user saves with greenlight provider" do
|
||||
post :create, params: user_params
|
||||
|
||||
u = User.last
|
||||
expect(u.provider).to eql("greenlight")
|
||||
end
|
||||
|
||||
it "renders #new on unsuccessful save" do
|
||||
post :create, params: invalid_params
|
||||
|
||||
expect(response).to render_template(:new)
|
||||
end
|
||||
end
|
||||
|
||||
describe "PATCH #update" do
|
||||
it "properly updates user attributes" do
|
||||
@user = create(:user)
|
||||
|
||||
patch :update, params: user_params.merge!(user_uid: @user)
|
||||
@user.reload
|
||||
|
||||
expect(@user.name).to eql("Example")
|
||||
expect(@user.email).to eql("example@example.com")
|
||||
end
|
||||
|
||||
it "properly updates user password" do
|
||||
|
||||
end
|
||||
|
||||
it "renders #edit on unsuccessful save" do
|
||||
@user = create(:user)
|
||||
|
||||
patch :update, params: invalid_params.merge!(user_uid: @user)
|
||||
expect(response).to render_template(:edit)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,10 +3,10 @@ require 'bigbluebutton_api'
|
|||
|
||||
describe Room, type: :model do
|
||||
|
||||
before {
|
||||
before do
|
||||
@user = create(:user)
|
||||
@room = @user.main_room
|
||||
}
|
||||
end
|
||||
|
||||
context 'validations' do
|
||||
it { should validate_presence_of(:name) }
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
require "rails_helper"
|
||||
|
||||
describe User, type: :model do
|
||||
before { @user = create(:user) }
|
||||
before do
|
||||
@user = create(:user)
|
||||
end
|
||||
|
||||
context 'validations' do
|
||||
it { should validate_presence_of(:name) }
|
||||
|
@ -55,7 +57,7 @@ describe User, type: :model do
|
|||
end
|
||||
|
||||
context '#from_omniauth' do
|
||||
it "should create user from omniauth" do
|
||||
let(:auth) {
|
||||
auth = {
|
||||
"uid" => "123456789",
|
||||
"provider" => "twitter",
|
||||
|
@ -66,7 +68,9 @@ describe User, type: :model do
|
|||
"image" => "example.png"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
it "should create user from omniauth" do
|
||||
expect {
|
||||
user = User.from_omniauth(auth)
|
||||
|
||||
|
|
Loading…
Reference in New Issue