Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improved users_controller_test suit #1596

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class User < ActiveRecord::Base
validates_length_of :password, within: 8..128, allow_blank: true
validates :github, presence: true, uniqueness: true
validates :email_frequency, inclusion: { in: EmailRateLimit::USER_STATES.map(&:to_s) + [nil], message: "Not a valid frequency, pick from #{EmailRateLimit::USER_STATES}" }

validates :email, format: { with: URI::MailTo::EMAIL_REGEXP }, allow_blank: true
# Setup accessible (or protected) attributes for your model

has_many :repo_subscriptions, dependent: :destroy
Expand Down
32 changes: 32 additions & 0 deletions test/functional/users_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,36 @@ class UsersControllerTest < ActionController::TestCase
delete :token_destroy, params: { account_delete_token: users(:mockstar).account_delete_token }
end
end

test "show user" do
sign_in users(:mockstar)
get :show, params: { id: users(:mockstar).id }
assert(response.status == 200)
end

test "update user" do
sign_in users(:mockstar)
patch :update, params: { id: users(:mockstar).id, user: { name: 'new name' } }
assert(User.find(users(:mockstar).id).name == 'new name')
end

test "don´t update user with invalid email" do
sign_in users(:mockstar)
patch :update, params: { id: users(:mockstar).id, user: { email: 'wrong_email' } }
assert(User.find(users(:mockstar).id).email != 'wrong_email')
end

test "update with blanck email" do
sign_in users(:mockstar)
patch :update, params: { id: users(:mockstar).id, user: { email: '' } }
assert(User.find(users(:mockstar).id).email == "")
end

test "update with valid email" do
sign_in users(:mockstar)
patch :update, params: { id: users(:mockstar).id, user: { email: '[email protected]'}}
assert(User.find(users(:mockstar).id).email == '[email protected]')
end


end