Commit 5664346c by tady

rspec, guard, test for User#google_oauth_token_expired?

parent fb5bf120
--color
...@@ -69,6 +69,14 @@ group :development do ...@@ -69,6 +69,14 @@ group :development do
gem 'pry-rails' gem 'pry-rails'
end end
group :development, :test do
gem 'rspec-rails'
gem 'guard-rspec'
gem 'factory_girl_rails'
gem 'spring'
end
group :production do group :production do
gem 'rails_12factor' gem 'rails_12factor'
gem 'pg' gem 'pg'
......
...@@ -53,6 +53,8 @@ GEM ...@@ -53,6 +53,8 @@ GEM
binding_of_caller (0.7.2) binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1) debug_inspector (>= 0.0.1)
builder (3.1.4) builder (3.1.4)
celluloid (0.15.2)
timers (~> 1.1.0)
coderay (1.1.0) coderay (1.1.0)
coffee-rails (4.0.1) coffee-rails (4.0.1)
coffee-script (>= 2.2.0) coffee-script (>= 2.2.0)
...@@ -71,13 +73,30 @@ GEM ...@@ -71,13 +73,30 @@ GEM
railties (>= 3.2.6, < 5) railties (>= 3.2.6, < 5)
thread_safe (~> 0.1) thread_safe (~> 0.1)
warden (~> 1.2.3) warden (~> 1.2.3)
diff-lcs (1.2.5)
erubis (2.7.0) erubis (2.7.0)
eventmachine (1.0.3) eventmachine (1.0.3)
execjs (2.0.2) execjs (2.0.2)
factory_girl (4.3.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.3.0)
factory_girl (~> 4.3.0)
railties (>= 3.0.0)
faraday (0.8.8) faraday (0.8.8)
multipart-post (~> 1.2.0) multipart-post (~> 1.2.0)
ffi (1.9.3)
formatador (0.2.4)
gmail_xoauth (0.4.1) gmail_xoauth (0.4.1)
oauth (>= 0.3.6) oauth (>= 0.3.6)
guard (2.2.4)
formatador (>= 0.2.4)
listen (~> 2.1)
lumberjack (~> 1.0)
pry (>= 0.9.12)
thor (>= 0.18.1)
guard-rspec (4.0.4)
guard (>= 2.1.1)
rspec (~> 2.14)
hashie (2.0.5) hashie (2.0.5)
hike (1.2.3) hike (1.2.3)
htmlentities (4.3.1) htmlentities (4.3.1)
...@@ -89,6 +108,11 @@ GEM ...@@ -89,6 +108,11 @@ GEM
json (1.8.1) json (1.8.1)
jwt (0.1.8) jwt (0.1.8)
multi_json (>= 1.5) multi_json (>= 1.5)
listen (2.2.0)
celluloid (>= 0.15.2)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
lumberjack (1.0.4)
mail (2.5.4) mail (2.5.4)
mime-types (~> 1.16) mime-types (~> 1.16)
treetop (~> 1.4.8) treetop (~> 1.4.8)
...@@ -152,8 +176,26 @@ GEM ...@@ -152,8 +176,26 @@ GEM
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
rake (10.1.0) rake (10.1.0)
rb-fsevent (0.9.3)
rb-inotify (0.9.2)
ffi (>= 0.5.0)
rdoc (3.12.2) rdoc (3.12.2)
json (~> 1.4) json (~> 1.4)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rspec-core (2.14.7)
rspec-expectations (2.14.4)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.4)
rspec-rails (2.14.0)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
sass (3.2.12) sass (3.2.12)
sass-rails (4.0.1) sass-rails (4.0.1)
railties (>= 4.0.0, < 5.0) railties (>= 4.0.0, < 5.0)
...@@ -163,6 +205,7 @@ GEM ...@@ -163,6 +205,7 @@ GEM
json (>= 1.1.3) json (>= 1.1.3)
rdoc (~> 3.10) rdoc (~> 3.10)
slop (3.4.7) slop (3.4.7)
spring (1.0.0)
sprockets (2.10.1) sprockets (2.10.1)
hike (~> 1.2) hike (~> 1.2)
multi_json (~> 1.0) multi_json (~> 1.0)
...@@ -181,6 +224,7 @@ GEM ...@@ -181,6 +224,7 @@ GEM
thread_safe (0.1.3) thread_safe (0.1.3)
atomic atomic
tilt (1.4.1) tilt (1.4.1)
timers (1.1.0)
treetop (1.4.15) treetop (1.4.15)
polyglot polyglot
polyglot (>= 0.3.1) polyglot (>= 0.3.1)
...@@ -202,7 +246,9 @@ DEPENDENCIES ...@@ -202,7 +246,9 @@ DEPENDENCIES
coderay coderay
coffee-rails (~> 4.0.0) coffee-rails (~> 4.0.0)
devise devise
factory_girl_rails
faraday faraday
guard-rspec
jbuilder (~> 1.2) jbuilder (~> 1.2)
mail mail
nokogiri nokogiri
...@@ -214,8 +260,10 @@ DEPENDENCIES ...@@ -214,8 +260,10 @@ DEPENDENCIES
rails (~> 4.0.2) rails (~> 4.0.2)
rails_12factor rails_12factor
redcarpet! redcarpet!
rspec-rails
sass-rails (~> 4.0.0) sass-rails (~> 4.0.0)
sdoc sdoc
spring
sqlite3 sqlite3
thin thin
uglifier (>= 1.3.0) uglifier (>= 1.3.0)
guard :rspec, spring: true do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { 'spec' }
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^spec/factories/(.+)\.rb$}) { 'spec/factories_spec.rb' }
watch(%r{^spec/support/(.+)\.rb$}) { 'spec' }
watch('config/routes.rb') { 'spec/routing' }
watch('app/controllers/application_controller.rb') { 'spec/controllers' }
end
FactoryGirl.define do
factory :alice, class: User do
email "alice@mail.com"
password Devise.friendly_token[0,20]
google_token_expires_at Time.now + 30.minutes
end
factory :bob, class: User do
email "bob@mail.com"
password Devise.friendly_token[0,20]
google_token_expires_at Time.now - 1.hour
end
end
require 'spec_helper'
describe User do
before :each do
@alice = create(:alice)
@bob = create(:bob)
end
describe '#google_oauth_token_expired?' do
it 'not expired' do
expect(@alice.google_oauth_token_expired?).to be_false
end
it 'expired' do
expect(@bob.google_oauth_token_expired?).to be_true
end
end
end
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'factory_girl'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# 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.
config.use_transactional_fixtures = true
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
config.include FactoryGirl::Syntax::Methods
config.before(:all) do
FactoryGirl.reload
end
end
require 'test_helper'
class HomeControllerTest < ActionController::TestCase
test "should get show" do
get :show
assert_response :success
end
end
require 'test_helper'
class PostsControllerTest < ActionController::TestCase
setup do
@post = posts(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:posts)
end
test "should get new" do
get :new
assert_response :success
end
test "should create post" do
assert_difference('Post.count') do
post :create, post: { body: @post.body, title: @post.title }
end
assert_redirected_to post_path(assigns(:post))
end
test "should show post" do
get :show, id: @post
assert_response :success
end
test "should get edit" do
get :edit, id: @post
assert_response :success
end
test "should update post" do
patch :update, id: @post, post: { body: @post.body, title: @post.title }
assert_redirected_to post_path(assigns(:post))
end
test "should destroy post" do
assert_difference('Post.count', -1) do
delete :destroy, id: @post
end
assert_redirected_to posts_path
end
end
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
title: MyString
body: MyText
two:
title: MyString
body: MyText
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
name: MyString
two:
name: MyString
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
require 'test_helper'
class HomeHelperTest < ActionView::TestCase
end
require 'test_helper'
class PostsHelperTest < ActionView::TestCase
end
require 'test_helper'
class PostTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class TagTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class UserTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
ENV["RAILS_ENV"] ||= "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
ActiveRecord::Migration.check_pending!
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
#
# Note: You'll currently still have to declare fixtures explicitly in integration tests
# -- they do not yet inherit this setting
fixtures :all
# Add more helper methods to be used by all tests here...
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment