From a7791635aa98f012d35f97c3c5288494bbb28e38 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Wed, 13 Mar 2024 18:03:43 +0100 Subject: Initial commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- test/models/user_test.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 test/models/user_test.rb (limited to 'test/models/user_test.rb') diff --git a/test/models/user_test.rb b/test/models/user_test.rb new file mode 100644 index 0000000..6ff5e19 --- /dev/null +++ b/test/models/user_test.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'test_helper' + +class UserTest < ActiveSupport::TestCase + test 'has to provide username and password' do + user = User.new + assert_raise(ActiveRecord::RecordInvalid) { user.save! } + + user.username = 'whatever' + assert_raise(ActiveRecord::RecordInvalid) { user.save! } + + user.password = '1234' + user.password_confirmation = '12345' + assert_raise(ActiveRecord::RecordInvalid) { user.save! } + + user.password_confirmation = '1234' + assert_difference('User.count') do + user.save! + end + end + + test 'username has to be unique' do + user = User.new(username: users(:user).username, + password: '1234', password_confirmation: '1234') + assert_raise(ActiveRecord::RecordInvalid) { user.save! } + end +end -- cgit v1.2.3