diff options
| author | mo khan <mo@mokhan.ca> | 2021-04-30 21:38:37 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2021-04-30 21:38:37 -0600 |
| commit | b85d5d43855501c9866c1ab4442aced3d4250664 (patch) | |
| tree | 0e6fc8a8381732bc9c64e877d36ccac207660ae5 /test | |
| parent | f24dfbde3eafcc9be39a7c246263d49b9a12fb3a (diff) | |
feat: generate users scaffold
Diffstat (limited to 'test')
| -rw-r--r-- | test/controllers/users_controller_test.rb | 28 | ||||
| -rw-r--r-- | test/fixtures/users.yml | 7 | ||||
| -rw-r--r-- | test/models/user_test.rb | 13 |
3 files changed, 48 insertions, 0 deletions
diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb new file mode 100644 index 0000000..cc871bc --- /dev/null +++ b/test/controllers/users_controller_test.rb @@ -0,0 +1,28 @@ +require "test_helper" + +class UsersControllerTest < ActionDispatch::IntegrationTest + setup do + @user = users(:billie) + end + + test "should get index" do + get users_url + assert_response :success + end + + test "should get new" do + get new_user_url + assert_response :success + end + + test "should create user" do + post users_url, params: { user: { handle: 'wycats' } } + + assert_redirected_to user_url(User.last) + end + + test "should show user" do + get user_url(@user) + assert_response :success + end +end diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml new file mode 100644 index 0000000..fd4026e --- /dev/null +++ b/test/fixtures/users.yml @@ -0,0 +1,7 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +mona: + handle: monalisa + +billie: + handle: billie diff --git a/test/models/user_test.rb b/test/models/user_test.rb new file mode 100644 index 0000000..4a1a7ad --- /dev/null +++ b/test/models/user_test.rb @@ -0,0 +1,13 @@ +require "test_helper" + +class UserTest < ActiveSupport::TestCase + test "creating a new user" do + assert User.create(handle: 'eilish') + end + + test "cannot create a duplicate user" do + assert_raises do + User.create!(handle: 'billie') + end + end +end |
