== README
rails new TLLrails -d postgresql
initial commit and remote add to respository
gco -b setup
add bootstrap, follow diections here: https://github.com/twbs/bootstrap-rubygem
- rake db:create
rails g sorcery:install (creates model and migration)
check the migration is how you want then:
rails generate controller users new show index create
add strong params in user controller: def user_params params.require(:user).permit(:name, :email, :password, :password_confirmation) end
add validations to user model:
class User < ActiveRecord::Base
authenticates_with_sorcery!
validates :password, length: { minimum: 3 }, if: -> { new_record? || changes[:crypted_password] }
validates :password, confirmation: true, if: -> { new_record? || changes[:crypted_password] }
validates :password_confirmation, presence: true, if: -> { new_record? || changes[:crypted_password] }
validates :email, uniqueness: true
end
add routes to controller
create new form for User -- run it and test to see if works
setup so that users can log in:
create form for user/new <%= form_for @user do |f| %> <% if f.object.errors.any?%>
Error: <%= x %>
User was not saved
<% end %> <% end %>
<div>
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div>
<%= f.label :password %><br />
<%= f.password_field :password %>
</div>
<div>
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %>
</div>
<div>
<%= f.submit %>
</div>
<% end %>
<% end %>
test_helper.rb
: # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
# Add more helper methods to be used by all tests here...
end
class ActionController::TestCase
include Sorcery::TestHelpers::Rails::Integration
include Sorcery::TestHelpers::Rails::Controller
end
This lets you use the Sorcery test-helpers for controller and integration tests.
login_user(user=@user, route=login_path)
This assumes that in test/fixtures/users.yml
you've defined a default_user
fixture, but you can easily replace that top line with something like this:
If you want to define a fixture, it should look sort of like the fixture here: https://github.com/NoamB/sorcery/wiki/Testing-Rails (the very top item), though you might not need an 'activation_state'.
Here's the fixture I've used:
default_user:
email: "default_user@example.com"
salt: <%= salt = "asdasdastr4325234324sdfds" %>
crypted_password: <%= Sorcery::CryptoProviders::BCrypt.encrypt("secret", salt) %>