rework tests

This commit is contained in:
Josh
2018-06-15 14:41:07 -04:00
parent 8cffc4872c
commit 086a39ca3d
35 changed files with 96 additions and 594 deletions

View File

View File

@ -1,7 +0,0 @@
require 'test_helper'
class MainControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end

View File

@ -1,7 +0,0 @@
require 'test_helper'
class MeetingsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end

View File

@ -1,32 +0,0 @@
require 'test_helper'
class RoomsControllerTest < ActionDispatch::IntegrationTest
def setup
@steve = users(:steve)
@mark = users(:mark)
@kitchen = rooms(:kitchen)
@garage = rooms(:garage)
end
test 'should redirect to root if not logged in.' do
get room_path(@kitchen.uid)
assert_redirected_to root_path
end
test 'should redirect to correct room if incorrect room.' do
post create_session_path, params: {session: {email: @mark.email, password: "mark12345"}}
get room_path(@kitchen.uid)
assert_redirected_to room_path(@garage.uid)
end
test 'should render room if user is owner.' do
post create_session_path, params: {session: {email: @steve.email, password: "steve12345"}}
get room_path(@kitchen.uid)
assert_response :success
end
end

View File

@ -1,70 +0,0 @@
require 'test_helper'
class SessionsControllerTest < ActionDispatch::IntegrationTest
def setup
@steve = users(:steve)
@kitchen = rooms(:kitchen)
@steve.room = @kitchen
end
test 'can signin with greenlight account.' do
post create_session_path, params: {session: {email: @steve.email, password: "steve12345"}}
assert_redirected_to room_path(@steve.room.uid)
assert @steve.id, session[:user_id]
end
test 'can signup/login with omniauth.' do
email = "omniauth@test.com"
uid = "123456789"
OmniAuth.config.add_mock(:twitter, {
provider: "twitter",
uid: uid,
info: {
email: email,
name: "Omni User",
nickname: "username"
}
})
#get "/auth/twitter"
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:twitter]
#get omniauth_session_path(provider: "twitter")
user = User.find_by(email: email, uid: uid)
assert_not_nil user
assert_redirected_to room_path(user.room.uid)
assert user.id, session[:user_id]
end
test 'handles omniauth failure.' do
OmniAuth.config.on_failure = Proc.new do |env|
OmniAuth::FailureEndpoint.new(env).redirect_to_failure
end
OmniAuth.config.mock_auth[:twitter] = :invalid_credentials
get "/auth/twitter"
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:twitter]
assert_no_difference 'User.count' do
get omniauth_session_path(provider: "twitter")
end
assert_redirected_to auth_failure_path(message: "invalid_credentials", strategy: "twitter")
end
test 'can logout.' do
post create_session_path, params: {session: {email: @steve.email, password: "steve12345"}}
assert @steve.id, session[:user_id]
get logout_path
assert_not_equal @steve.id, session[:user_id]
end
end

View File

@ -1,22 +0,0 @@
require 'test_helper'
class UsersControllerTest < ActionDispatch::IntegrationTest
test 'can signup for greenlight account.' do
post signup_path, params: {
user: {
name: "Greenlight User",
username: "greenlight_user",
email: "greenlight@example.com",
password: "password",
password_confirmation: "password"
}
}
user = User.find_by(email: "greenlight@example.com")
assert_not_nil user
assert_redirected_to room_path(user.room.uid)
assert user.id, session[:user_id]
end
end

0
test/fixtures/.keep vendored
View File

View File

View File

@ -1,9 +0,0 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
breakfast:
name: "Breakfast"

View File

@ -1,14 +0,0 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
kitchen:
user: steve
uid: "13579"
garage:
user: mark
uid: "02468"

View File

@ -1,20 +0,0 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
steve:
name: "Steve User"
username: "steve"
provider: "greenlight"
email: "steve@example.com"
password_digest: <%= BCrypt::Password.create('steve12345') %>
mark:
name: "Mark User"
username: "mark"
provider: "greenlight"
email: "mark@example.com"
password_digest: <%= BCrypt::Password.create('mark12345') %>

View File

View File

View File

View File

View File

@ -1,23 +0,0 @@
require 'test_helper'
class MeetingTest < ActiveSupport::TestCase
def setup
@steve = users(:steve)
@kitchen = rooms(:kitchen)
@breakfast = meetings(:breakfast)
@breakfast.room = @kitchen
end
test "name should be present." do
@breakfast.name = nil
assert_not @breakfast.valid?
end
test "should set uid on creation." do
@breakfast.send(:generate_meeting_id)
assert @breakfast.uid
end
end

View File

@ -1,20 +0,0 @@
require 'test_helper'
class RoomTest < ActiveSupport::TestCase
def setup
@steve = users(:steve)
@mark = users(:mark)
@kitchen = rooms(:kitchen)
@kitchen.user = @steve
end
test "#owned_by? should identify correct owner." do
assert @kitchen.owned_by?(@steve)
end
test "#owned_by? should identify incorrect owner." do
assert_not @kitchen.owned_by?(@mark)
end
end

View File

@ -1,118 +0,0 @@
require 'test_helper'
class UserTest < ActiveSupport::TestCase
def setup
@steve = users(:steve)
end
test "should be valid." do
assert @steve.valid?
end
test "name should be present." do
@steve.name = nil
assert_not @steve.valid?
end
test "should allow nil email." do
@steve.email = nil
assert @steve.valid?
end
test "username should be present." do
@steve.username = nil
assert_not @steve.valid?
end
test "provider should be present." do
@steve.provider = nil
assert_not @steve.valid?
end
test "should allow nil uid." do
@steve.uid = nil
assert @steve.valid?
end
test "should allow nil password." do
@steve.password = @steve.password_confirmation = nil
assert @steve.valid?
end
test "password should be longer than 6 characters if it exists." do
@steve.password = "short"
assert_not @steve.valid?
end
test "should create user from omniauth" do
auth = {
"uid" => "123456789",
"provider" => "twitter",
"info" => {
"name" => "Test Name",
"nickname" => "username",
"email" => "test@example.com"
}
}
assert_difference 'User.count' do
User.from_omniauth(auth)
end
user = User.find_by(uid: auth["uid"], provider: auth["provider"])
assert user.username, auth["info"]["nickname"]
assert user.name, auth["info"]["name"]
end
test "email addresses should be saved as lower-case." do
mixed_case = "ExAmPlE@eXaMpLe.CoM"
@steve.email = mixed_case
@steve.save
assert_equal mixed_case.downcase, @steve.email
end
test "email validation should reject invalid addresses." do
invalid_addresses = %w[user@example,com user_at_foo.org user.name@example. foo@bar_baz.com foo@bar+baz.com]
invalid_addresses.each do |invalid_address|
@steve.email = invalid_address
assert_not @steve.valid?, "#{invalid_address.inspect} should be invalid."
end
end
test "email should be unique." do
duplicate_user = @steve.dup
duplicate_user.email = @steve.email.upcase
@steve.save
assert_not duplicate_user.valid?
end
test "name should not be too long." do
@steve.name = "a" * 25
assert_not @steve.valid?
end
test "email should not be too long." do
@steve.email = "a" * 50 + "@example.com"
assert_not @steve.valid?
end
test "password should have a minimum length." do
@steve.password = @steve.password_confirmation = "a" * 5
assert_not @steve.valid?
end
test "should authenticate on valid password." do
assert @steve.authenticate("steve12345")
end
test "should not authenticate on invalid password." do
assert_not @steve.authenticate('incorrect')
end
test "#initialize_room should create room." do
@steve.send(:initialize_room)
assert @steve.room
end
end

View File

@ -1,10 +0,0 @@
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
OmniAuth.config.test_mode = true
end