Commit 1e2c9a53 by tady

setup turnip & devise login mock

parent a44eaa40
...@@ -95,7 +95,7 @@ group :test do ...@@ -95,7 +95,7 @@ group :test do
gem 'capybara' gem 'capybara'
gem 'launchy' gem 'launchy'
gem 'poltergeist' gem 'poltergeist'
gem 'coveralls', :require => false gem 'coveralls', require: false
gem 'turnip' gem 'turnip'
end end
......
...@@ -12,13 +12,13 @@ class User < ActiveRecord::Base ...@@ -12,13 +12,13 @@ class User < ActiveRecord::Base
# Device # Device
def self.find_for_google_oauth2(access_token, signed_in_resource = nil) def self.find_for_google_oauth2(access_token, signed_in_resource = nil)
data = access_token.info info = access_token.info
user = User.where(email: data['email']).first user = User.where(email: info['email']).first
unless user unless user
user = User.create(name: data['name'], user = User.create(name: info['name'],
image_url: data['image'], image_url: info['image'],
email: data['email'], email: info['email'],
password: Devise.friendly_token[0, 20] password: Devise.friendly_token[0, 20]
) )
end end
......
<!-- view:home/login -->
<div class="login"> <div class="login">
<!-- Marketing messaging and featurettes <!-- Marketing messaging and featurettes
......
<!-- view:post/index -->
<div class="row"> <div class="row">
<div class="col-xs-6 col-md-4" id="sidebar" role="navigation"> <div class="col-xs-6 col-md-4" id="sidebar" role="navigation">
......
Feature: アクセス制限
Scenario: 非ログイン --> TOPページ
When visit '/'
Then response code is 200
Then response includes '<!-- view:home/login -->'
Scenario: 非ログイン --> postsページ
When visit '/posts'
Then response code is 200
Then response includes '<!-- view:home/login -->'
# Scenario: 禁止ユーザーログイン --> TOPページ
# Given login via google with 'taro@example.com'
# Then response code is 200
# Then page includes 'Your email address is not permitted'
# Scenario: 禁止ユーザーログイン --> postsページ
# Given login via google with 'taro@example.com'
# When visit '/posts'
# Then response code is 200
# Then response includes '<!-- view:home/login -->'
Scenario: ログイン --> TOPページ
Given user login
When visit '/'
Then response code is 200
Then response includes '<!-- view:post/index -->'
Scenario: ログイン --> postsページ
Given user login
When visit '/posts'
Then response code is 200
Then response includes '<!-- view:post/index -->'
Feature: ログインしていないユーザーのアクセス
Scenario: TOPページにアクセス
When visit '/'
Then response code is '200'
Scenario: TOP以外にアクセス
When visit '/posts'
Then response code is '999'
...@@ -86,4 +86,14 @@ RSpec.configure do |config| ...@@ -86,4 +86,14 @@ RSpec.configure do |config|
config.after :each do config.after :each do
DatabaseRewinder.clean DatabaseRewinder.clean
end end
OmniAuth.config.test_mode = true
OmniAuth.config.add_mock(:google_oauth2, {
'uid' => '12345',
'provider' => 'google_oauth2',
'info' => {'name' => 'Taro Yamada', 'email' => 'taro@zigexn.co.jp'},
'credentials' => {'token' => 'aaaaa', 'refresh_token' => 'bbbbb', 'expires_at' => 9999999999}
})
end end
...@@ -10,10 +10,18 @@ step 'response code is :code' do |code| ...@@ -10,10 +10,18 @@ step 'response code is :code' do |code|
expect(page.status_code.to_i).to eq(code.to_i) expect(page.status_code.to_i).to eq(code.to_i)
end end
step 'response include :string' do |string| step 'page includes :string' do |string|
expect(page).to have_content(string) expect(page).to have_content(string)
end end
step 'response includes :string' do |string|
expect(page.body).to include(string)
end
step 'h1 include :string' do |string| step 'h1 include :string' do |string|
expect(page.find('h1')).to have_content(string) expect(page.find('h1')).to have_content(string)
end end
step 'user login' do
visit '/users/auth/google_oauth2'
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