Permalink
Browse files

Setup test and make first passing one

  • Loading branch information...
GregPK committed Jun 29, 2015
1 parent 295d890 commit eb0bbed042bd98de2e41c1ba2188ca8c8766b875
Showing with 26 additions and 12 deletions.
  1. +4 −2 Gemfile
  2. +4 −0 Gemfile.lock
  3. +6 −5 app/models/user.rb
  4. +3 −0 config/environments/test.rb
  5. +2 −2 test/fixtures/users.yml
  6. +7 −3 test/models/user_test.rb
View
@@ -22,10 +22,12 @@ gem 'omniauth'
# Deploy with Capistrano
# gem 'capistrano', :group => :development
-gem 'figaro'
+group :test do
+ gem 'minitest-spec-rails'
+end
-# To use debugger
group :development do
+ gem 'figaro'
gem 'pry'
gem 'pry-byebug'
gem 'pry-stack_explorer'
View
@@ -69,6 +69,9 @@ GEM
mime-types (2.6.1)
mini_portile (0.6.2)
minitest (5.7.0)
+ minitest-spec-rails (5.2.2)
+ minitest (~> 5.0)
+ rails (~> 4.1)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
omniauth (1.2.2)
@@ -140,6 +143,7 @@ PLATFORMS
DEPENDENCIES
devise
figaro
+ minitest-spec-rails
omniauth
pg
pry
View
@@ -3,7 +3,11 @@ class User < ActiveRecord::Base
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
- before_save :ensure_authentication_token
+
+ def initialize
+ super
+ ensure_authentication_token
+ end
def ensure_authentication_token
if authentication_token.blank?
@@ -14,9 +18,6 @@ def ensure_authentication_token
private
def generate_authentication_token
- loop do
- token = Devise.friendly_token
- break token unless User.where(authentication_token: token).first
- end
+ Devise.friendly_token
end
end
@@ -36,4 +36,7 @@
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
+
+
+ config.active_support.test_order = :random
end
View
@@ -4,8 +4,8 @@
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
-one: {}
+#one: {}
# column: value
#
-two: {}
+#two: {}
# column: value
View
@@ -1,7 +1,11 @@
require 'test_helper'
class UserTest < ActiveSupport::TestCase
- # test "the truth" do
- # assert true
- # end
+ let(:user_new) { User.new{|u| u.email = 'ken@metaskills.net'} }
+
+ describe "for new user" do
+ it "should generate a new token on instantiation" do
+ user_new.authentication_token.wont_be_empty
+ end
+ end
end

0 comments on commit eb0bbed

Please sign in to comment.