add user scaffold
This commit is contained in:
5
spec/factories/users.rb
Normal file
5
spec/factories/users.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
username { "xpto" }
|
||||
end
|
||||
end
|
||||
36
spec/models/user_spec.rb
Normal file
36
spec/models/user_spec.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe User, type: :model do
|
||||
describe 'validations' do
|
||||
describe 'username' do
|
||||
it 'presence' do
|
||||
user = build(:user, username: nil)
|
||||
|
||||
expect(user).to_not be_valid
|
||||
end
|
||||
|
||||
it 'uniqueness' do
|
||||
create(:user, username: 'xpto')
|
||||
user = build(:user, username: 'xpto')
|
||||
|
||||
expect(user).to_not be_valid
|
||||
end
|
||||
|
||||
it 'max length 14' do
|
||||
with_15_caracters = build(:user, username: 'asdfghjklzxcvhn')
|
||||
with_14_caracters = build(:user, username: 'asdfghjklzxcvh')
|
||||
|
||||
expect(with_15_caracters).to_not be_valid
|
||||
expect(with_14_caracters).to be_valid
|
||||
end
|
||||
|
||||
it 'format' do
|
||||
with_invalid_format = build(:user, username: 'asdfghjklzxcvh!')
|
||||
with_valid_format = build(:user, username: 'asdfghjklzxcvh')
|
||||
|
||||
expect(with_invalid_format).to_not be_valid
|
||||
expect(with_valid_format).to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -34,6 +34,8 @@ RSpec.configure do |config|
|
||||
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
||||
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
||||
|
||||
config.include FactoryBot::Syntax::Methods
|
||||
|
||||
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
||||
# examples within a transaction, remove the following line or assign false
|
||||
# instead of true.
|
||||
@@ -62,10 +64,3 @@ RSpec.configure do |config|
|
||||
# arbitrary gems may also be filtered via:
|
||||
# config.filter_gems_from_backtrace("gem name")
|
||||
end
|
||||
|
||||
Shoulda::Matchers.configure do |config|
|
||||
config.integrate do |with|
|
||||
with.test_framework :rspec
|
||||
with.library :rails
|
||||
end
|
||||
end
|
||||
|
||||
17
spec/requests/users_spec.rb
Normal file
17
spec/requests/users_spec.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "/users", type: :request do
|
||||
let(:valid_attributes) {
|
||||
{
|
||||
username: 'geonizeli'
|
||||
}
|
||||
}
|
||||
|
||||
describe "GET /show" do
|
||||
it "renders a successful response" do
|
||||
user = User.create! valid_attributes
|
||||
get user_url(user), as: :json
|
||||
expect(response).to be_successful
|
||||
end
|
||||
end
|
||||
end
|
||||
9
spec/routing/users_routing_spec.rb
Normal file
9
spec/routing/users_routing_spec.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe UsersController, type: :routing do
|
||||
describe "routing" do
|
||||
it "routes to #show" do
|
||||
expect(get: "/users/1").to route_to("users#show", id: "1")
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user