dailycred 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
- metadata.gz: 347a55fb9eae49897183cd5bab9ba6b7316c6215
4
- data.tar.gz: ca8ce17bab65de8228d0898cc509b8301ed0bed7
3
+ metadata.gz: ba1c79148b0ed6cfbba255f0cc520f0eee2a6bb8
4
+ data.tar.gz: 635fd2685f642397c15e74c64237cdcfae8595bc
5
5
  !binary "U0hBNTEy":
6
- metadata.gz: a463c7d68d9a0264595d7b76a2bf4bf4a1d0ef838c93274630352b96ec8f1f05569d2c0dfebb2a37bc1af43304d735f4a0f302c40f999e225542cef2691a3bdf
7
- data.tar.gz: f496ca9d9213cef0b0a390bf78865d4d363dbd002aaaafb46be0d6e053bde5fdbd7b93159648c1868d78eba882a1e980aed4e220164a9cb504a71769d8093731
6
+ metadata.gz: 276cb40be36dcbaa8c64e2753f8516945fd3e990cfd09c842305ca09aebdc5c4caa9655ce7f8cca6bae9199f182adc83623caa373d09ed333acf24f353abceb5
7
+ data.tar.gz: d2da9e81f623325dd9005a14ea1ca3d1ae5a5d1ee979bca42301de13805d9f8a538c75c05030955a1b470de16159bedecfc1bc19164c7f4c21920ac16e4663aa
data/.DS_Store ADDED
Binary file
data/Gemfile CHANGED
@@ -15,4 +15,4 @@ gem 'fl-rocco'
15
15
  gem 'redcarpet', '~> 1.17'
16
16
  gem 'markdown'
17
17
  gem 'maruku'
18
- gem 'faraday'
18
+ gem 'faraday'
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  The Dailycred ruby gem is everything you need to get off the ground running with robust authentication. It includes an [omniauth](https://github.com/intridea/omniauth) provider and a generator to create necessary models and controllers. The generated authentication structure is inspired by [nifty-generators](https://github.com/ryanb/nifty-generators).
4
4
 
5
+ If you are using a rails project that already has authentication, check out this post about [integrating Dailycred with an existing rails project](https://www.dailycred.com/blog/15/how-to-integrate-dailycred-with-an-existing-rails-project).
6
+
5
7
  If you'd rather only communicate with Dailycred through OAuth and provide your own authentication controllers and models, you can use the [omniauth_dailycred](https://github.com/dailycred/omniauth_dailycred) gem.
6
8
 
7
9
  ##Installation
@@ -13,7 +15,7 @@ To get started using Dailycred with Ruby on Rails, the first thing you need to d
13
15
  Make sure you've signed up for Dailycred, and head over to your [settings](https://www.dailycred.com/admin/settings) page to get your API keys. Once you've done that, head back to the command line and run:
14
16
 
15
17
  bundle
16
- rails g dailycred
18
+ rails g dailycred:install
17
19
  rake db:migrate
18
20
 
19
21
  Thats it! You've successfully added authentication to your app, and you can start signing up users. Run `rails s` to start your
@@ -218,15 +220,14 @@ To specify where users should be redirected after authentication actions, setup
218
220
  # :after_auth => '/hello', #after login
219
221
  # :after_unauth => '/goodbye' #after logout
220
222
  # }
223
+
224
+ ### Customization
221
225
 
222
- ## Contributing
223
-
224
- 1. Fork it
225
- 2. Create your feature branch (`git checkout -b my-new-feature`)
226
- 3. Commit your changes (`git commit -am 'Added some feature'`)
227
- 4. Push to the branch (`git push origin my-new-feature`)
228
- 5. Create new Pull Request
226
+ If you would like to customize this engine's `session_controller` or views, two generators are provided for you.
229
227
 
230
- ![](https://www.dailycred.com/dc.gif?client_id=dailycred&title=rails_repo "dailycred")
228
+ rails g dailycred:controllers
229
+ rails g dailycred:views
230
+
231
+ ![](https://www.dailycred.com/dc.gif?client_id=dailycred&title=rails_repo&type=rails_repo "dailycred")
231
232
 
232
233
  [![Build Status](https://secure.travis-ci.org/dailycred/dailycred.png?branch=master)](https://travis-ci.org/dailycred/dailycred)
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
3
  require 'rspec/core/rake_task'
4
+ require 'rake/testtask'
4
5
 
5
6
  desc "Run specs"
6
7
  RSpec::Core::RakeTask.new do |t|
@@ -10,13 +11,28 @@ end
10
11
 
11
12
  desc "run travis"
12
13
  task :travis do
13
- ["rake spec","ruby test/test_helper.rb"].each do |cmd|
14
+ ["rake spec","rake test"].each do |cmd|
14
15
  puts "Starting to run #{cmd}..."
15
16
  system("export DISPLAY=:99.0 && bundle exec #{cmd}")
16
17
  raise "#{cmd} failed!" unless $?.exitstatus == 0
17
18
  end
18
19
  end
19
20
 
21
+ # desc "generator tests"
22
+ # task :test do
23
+ # system "bundle exec ruby test/test_helper.rb"
24
+ # raise "test::unit failed!" unless $?.exitstatus == 0
25
+ # end
26
+
27
+ desc 'Run Devise unit tests.'
28
+ Rake::TestTask.new(:test) do |t|
29
+ t.libs << 'lib'
30
+ t.libs << 'test'
31
+ t.pattern = 'test/**/*_test.rb'
32
+ # t.verbose = true
33
+ # t.warning = true
34
+ end
35
+
20
36
  task :default => :travis
21
37
 
22
38
  desc 'docs'
@@ -31,7 +47,7 @@ task :docs do
31
47
  md = ""
32
48
  File.open("README.md", "r") do |infile|
33
49
  while (line = infile.gets)
34
- md += line
50
+ md += line.gsub(/(<code>HTML|javascript|ruby)/, "<code>")
35
51
  end
36
52
  end
37
53
  doc = Maruku.new(md)
Binary file
@@ -0,0 +1,33 @@
1
+ module Dailycred
2
+ class SessionsController < ApplicationController
3
+ before_filter :authenticate, :only => [:destroy]
4
+ before_filter :current_user
5
+ include Dailycred::Helpers
6
+
7
+ # Callback Route for OAuth flow
8
+ def create
9
+ @user = User.find_or_create_with_omniauth auth_hash
10
+ session[:user_id] = @user.id
11
+ redirect_to_auth
12
+ end
13
+
14
+ #GET /logout
15
+ def destroy
16
+ session[:user_id] = nil
17
+ redirect_to_unauth
18
+ end
19
+
20
+ def failure
21
+ redirect_to_unauth notice: params[:message]
22
+ end
23
+
24
+ def info
25
+ end
26
+
27
+ private
28
+
29
+ def auth_hash
30
+ h = request.env['omniauth.auth']
31
+ end
32
+ end
33
+ end
Binary file
Binary file
data/config/routes.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  Dailycred::Engine.routes.draw do
2
- get "/:provider/callback" => "sessions#create"
3
- get "/logout" => "sessions#destroy", :as => :logout
4
- get "/" => "sessions#info", :as => :auth_info
2
+ get "/:provider/callback" => "dailycred/sessions#create"
3
+ get "/logout" => "dailycred/sessions#destroy", :as => :logout
4
+ get "/" => "dailycred/sessions#info", :as => :auth_info
5
5
  # get "/dailycred", :as => :login
6
- get "/failure" => "sessions#failure"
6
+ get "/failure" => "dailycred/sessions#failure"
7
7
  end
@@ -1,4 +1,16 @@
1
1
  class ApplicationController < ActionController::Base
2
+ helper_method :current_user
3
+
4
+ private
5
+
6
+ # helper method for getting the current signed in user
7
+ def current_user
8
+ begin
9
+ @current_user || User.find(session[:user_id]) if session[:user_id]
10
+ rescue
11
+ nil
12
+ end
13
+ end
2
14
  helper_method :current_user
3
15
 
4
16
  private
@@ -0,0 +1,33 @@
1
+ module Dailycred
2
+ class SessionsController < ApplicationController
3
+ before_filter :authenticate, :only => [:destroy]
4
+ before_filter :current_user
5
+ include Dailycred::Helpers
6
+
7
+ # Callback Route for OAuth flow
8
+ def create
9
+ @user = User.find_or_create_with_omniauth auth_hash
10
+ session[:user_id] = @user.id
11
+ redirect_to_auth
12
+ end
13
+
14
+ #GET /logout
15
+ def destroy
16
+ session[:user_id] = nil
17
+ redirect_to_unauth
18
+ end
19
+
20
+ def failure
21
+ redirect_to_unauth notice: params[:message]
22
+ end
23
+
24
+ def info
25
+ end
26
+
27
+ private
28
+
29
+ def auth_hash
30
+ h = request.env['omniauth.auth']
31
+ end
32
+ end
33
+ end
Binary file
Binary file
@@ -0,0 +1,13 @@
1
+ <% if current_user %>
2
+ <p>Hello <%= current_user.email %> <br>
3
+ <%= link_to 'Logout', dailycred_engine.logout_path %>
4
+ <br><%= link_to 'connect with facebook', connect_user(:facebook) %>
5
+ <br><%= link_to 'connect with google', connect_user(:google) %>
6
+ <br><%= link_to 'connect with twitter', connect_user(:twitter) %>
7
+ </p>
8
+ <% else %>
9
+ <%= link_to 'Log In', login_path() %>
10
+ <br><%= link_to 'connect with facebook', connect_path(:identity_provider => :facebook) %>
11
+ <br><%= link_to 'connect with google', connect_path(:identity_provider => :google) %>
12
+ <br><%= link_to 'connect with twitter',connect_path(:identity_provider => :twitter) %>
13
+ <% end %>
@@ -1,4 +1,5 @@
1
1
  Dummy::Application.routes.draw do
2
+ mount Dailycred::Engine => '/auth', :as => 'dailycred_engine'
2
3
  #mount Dailycred::Engine => '/auth', :as => 'dailycred_engine'
3
4
  # The priority is based upon order of creation: first created -> highest priority.
4
5
  # See how all your routes lay out with "rake routes".
@@ -1,3 +1,3 @@
1
1
  module Dailycred
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -0,0 +1,12 @@
1
+ require 'rails/generators'
2
+ module Dailycred
3
+ module Generators
4
+ class ControllersGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../../../../app/controllers/', __FILE__)
6
+
7
+ def copy_controllers
8
+ directory "dailycred", "app/controllers/dailycred"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,62 @@
1
+ require 'rails/generators'
2
+ require 'test_helper'
3
+ module Dailycred
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ source_root File.expand_path('../../templates', __FILE__)
7
+
8
+ CLIENT_ID_DEFAULT = 'YOUR_CLIENT_ID'
9
+ CLIENT_SECRET_DEFAULT = 'YOUR_SECRET_KEY'
10
+
11
+ argument :client_id, :type => :string, :default => CLIENT_ID_DEFAULT, :banner => 'dailycred_client_id'
12
+ argument :secret_key, :type => :string, :default => CLIENT_SECRET_DEFAULT, :banner => 'dailycred_secret_key'
13
+ class_option :bootstrap, :type => :boolean, :default => true,
14
+ :description => "Indicates whether you want to generate the user model (with migration)
15
+ and mount the engine's sessions_controller.
16
+ Use --skip-bootstrap if you want are adding this to project that already has authentication
17
+ and you only want to use the Omniauth adapter and helper methods."
18
+
19
+
20
+ APP_ROUTES_LINES =<<-EOS
21
+ mount Dailycred::Engine => '/auth', :as => 'dailycred_engine'
22
+ EOS
23
+
24
+ APP_CONTROLLER_LINES =<<-EOS
25
+ helper_method :current_user
26
+
27
+ private
28
+
29
+ # helper method for getting the current signed in user
30
+ def current_user
31
+ begin
32
+ @current_user || User.find(session[:user_id]) if session[:user_id]
33
+ rescue
34
+ nil
35
+ end
36
+ end
37
+ EOS
38
+
39
+ def install
40
+ puts 'installing'
41
+ # copy initializer
42
+ template "omniauth.rb", "config/initializers/omniauth.rb"
43
+ # get client info from login if they didnt specify info
44
+ puts "Please manually configure your API keys in config/initializers/omniauth.rb"
45
+ if options.bootstrap?
46
+ # application controller
47
+ insert_into_file "app/controllers/application_controller.rb", APP_CONTROLLER_LINES, :after => /class ApplicationController\n|class ApplicationController .*\n/
48
+ # user model
49
+ copy_file "user.rb", "app/models/user.rb"
50
+ # user migration
51
+ copy_file "migration_create_user.rb", "db/migrate/#{Time.now.strftime('%Y%m%d%H%M%S')}_create_users.rb"
52
+ # confiffg/routes
53
+ inject_into_file "config/routes.rb", APP_ROUTES_LINES, :after => ".draw do\n"
54
+ else
55
+ puts "Make sure you implement your omniauth callback. For directions visit https://github.com/intridea/omniauth#integrating-omniauth-into-your-application"
56
+ end
57
+ end
58
+
59
+
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,12 @@
1
+ require 'rails/generators'
2
+ module Dailycred
3
+ module Generators
4
+ class ViewsGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../../../../app/views/', __FILE__)
6
+
7
+ def copy_views
8
+ directory "dailycred", "app/views/dailycred"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -36,6 +36,7 @@ class DailycredGenerator < Rails::Generators::Base
36
36
  EOS
37
37
 
38
38
  def install
39
+ puts "DEPRECATED: calling `rails generate dailycred` has been deprecated. Please use `rails generate dailycred:install`."
39
40
  # copy initializer
40
41
  template "omniauth.rb", "config/initializers/omniauth.rb"
41
42
  # get client info from login if they didnt specify info
data/test/.DS_Store ADDED
Binary file
@@ -0,0 +1,13 @@
1
+ require 'test_helper'
2
+ class ViewsGeneratorTest < Rails::Generators::TestCase
3
+
4
+ include Dailycred::GeneratorTestHelpers
5
+ destination File.expand_path("../support/tmp/myproject", File.dirname(__FILE__))
6
+ tests Dailycred::Generators::ControllersGenerator
7
+
8
+ test "creates correct controller files" do
9
+ run_generator
10
+ assert_file "app/controllers/dailycred/sessions_controller.rb"
11
+ end
12
+
13
+ end
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+ class InstallGeneratorTest < Rails::Generators::TestCase
3
+
4
+ include Dailycred::GeneratorTestHelpers
5
+ include Dailycred::GeneratorTest
6
+ destination File.expand_path("../support/tmp/myproject", File.dirname(__FILE__))
7
+ tests Dailycred::Generators::InstallGenerator
8
+
9
+ test "install generator works with input" do
10
+ test_generator ["aaa","bbb"]
11
+ assert_credentials "aaa", "bbb"
12
+ end
13
+
14
+ test "install generator works without input" do
15
+ test_generator
16
+ assert_credentials "YOUR_CLIENT_ID", "YOUR_SECRET_KEY"
17
+ end
18
+
19
+ test "install generator works without bootstrap" do
20
+ test_generator [], false
21
+ end
22
+
23
+ test "credentials work when skipping bootstrap" do
24
+ test_generator ["aaa", "bbb"], true
25
+ assert_credentials "aaa", "bbb"
26
+ end
27
+
28
+ end
@@ -0,0 +1,13 @@
1
+ require 'test_helper'
2
+ class ControllersGeneratorTest < Rails::Generators::TestCase
3
+
4
+ include Dailycred::GeneratorTestHelpers
5
+ destination File.expand_path("../support/tmp/myproject", File.dirname(__FILE__))
6
+ tests Dailycred::Generators::ViewsGenerator
7
+
8
+ test "creates correct view files" do
9
+ run_generator
10
+ assert_file "app/views/dailycred/sessions/info.html.erb"
11
+ end
12
+
13
+ end
@@ -0,0 +1,71 @@
1
+ module Dailycred
2
+ module GeneratorTestHelpers
3
+ def self.included base
4
+ base.setup :prepare_destination
5
+ base.teardown :remove_files
6
+ end
7
+
8
+ def prepare_destination
9
+ # Must set before requiring generator libs.
10
+ tmp_root = File.dirname(__FILE__) + "/tmp"
11
+ project_name = "myproject"
12
+ app_root = File.join(tmp_root, project_name)
13
+ @rails_root = app_root
14
+ FileUtils.mkdir_p @rails_root
15
+ Dir.mkdir("#{@rails_root}/config") unless File.exists?("#{@rails_root}/config")
16
+ File.open("#{@rails_root}/config/routes.rb", 'w') do |f|
17
+ f.puts "ActionController::Routing::Routes.draw do\n\nend"
18
+ end
19
+ Dir.mkdir("#{@rails_root}/app") unless File.exists?("#{@rails_root}/app")
20
+ Dir.mkdir("#{@rails_root}/app/controllers") unless File.exists?("#{@rails_root}/app/controllers")
21
+ File.open("#{@rails_root}/app/controllers/application_controller.rb", 'w') do |f|
22
+ f.puts "class ApplicationController < ActionController::Base\n\nend"
23
+ end
24
+ end
25
+
26
+ def remove_files
27
+ FileUtils.rm_rf File.dirname(__FILE__) + "/tmp"
28
+ end
29
+
30
+ def assert_credentials client_id, client_secret
31
+ assert_file "config/initializers/omniauth.rb" do |config|
32
+ assert config.include? "Rails.configuration.DAILYCRED_CLIENT_ID = \"#{client_id}\""
33
+ assert config.include? "Rails.configuration.DAILYCRED_SECRET_KEY = \"#{client_secret}\""
34
+ end
35
+ end
36
+
37
+ end
38
+ end
39
+
40
+ module Dailycred
41
+ module GeneratorTest
42
+ def test_generator args=[], bootstrap=true
43
+ unless bootstrap
44
+ args += ["a", "b"] if args.empty?
45
+ args << "--skip-bootstrap"
46
+ end
47
+ run_generator args
48
+ assert_file "config/initializers/omniauth.rb" do |config|
49
+ assert config.include? 'Rails.configuration.DAILYCRED_CLIENT_ID ='
50
+ assert config.include? 'Rails.configuration.DAILYCRED_SECRET_KEY ='
51
+ end
52
+
53
+ if bootstrap
54
+ assert_file "config/routes.rb", /(#{Regexp.escape("mount Dailycred::Engine => '/auth', :as => 'dailycred_engine'")})/
55
+
56
+ assert_file "app/models/user.rb" do |model|
57
+ assert model.include? "acts_as_dailycred"
58
+ end
59
+
60
+ assert_file "app/controllers/application_controller.rb" do |controller|
61
+ end
62
+
63
+ assert_migration "db/migrate/create_users.rb" do |migration|
64
+ end
65
+ else
66
+ assert_no_file "app/models/user.rb"
67
+ assert_no_migration "db/migrate/create_users.rb"
68
+ end
69
+ end
70
+ end
71
+ end
data/test/test_helper.rb CHANGED
@@ -1,6 +1,11 @@
1
1
  require 'test/unit'
2
- # require 'mocha/setup'
2
+ require 'rails/generators'
3
+ require 'fileutils'
3
4
 
5
+ Dir["./lib/*.rb"].each {|file| require file }
6
+ Dir["./lib/dailycred/*.rb"].each {|file| require file }
7
+ Dir["./lib/generators/dailycred/*.rb"].each {|file| require file }
8
+ Dir["./test/support/*.rb"].each {|file| require file }
9
+ require 'generators/dailycred_generator'
4
10
 
5
- require_relative './generator_test.rb'
6
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dailycred
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hank Stoever
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-23 00:00:00.000000000 Z
11
+ date: 2013-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth
@@ -45,6 +45,7 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - .DS_Store
48
49
  - .gitignore
49
50
  - .travis.yml
50
51
  - Gemfile
@@ -52,8 +53,11 @@ files:
52
53
  - LICENSE
53
54
  - README.md
54
55
  - Rakefile
55
- - app/controllers/sessions_controller.rb
56
- - app/views/sessions/info.html.erb
56
+ - app/controllers/.DS_Store
57
+ - app/controllers/dailycred/sessions_controller.rb
58
+ - app/views/.DS_Store
59
+ - app/views/dailycred/.DS_Store
60
+ - app/views/dailycred/sessions/info.html.erb
57
61
  - config/routes.rb
58
62
  - dailycred.gemspec
59
63
  - docs/lib/dailycred.html
@@ -159,11 +163,15 @@ files:
159
163
  - dummy/app/assets/stylesheets/application.css
160
164
  - dummy/app/controllers/application_controller.rb
161
165
  - dummy/app/controllers/concerns/.keep
166
+ - dummy/app/controllers/dailycred/sessions_controller.rb
162
167
  - dummy/app/helpers/application_helper.rb
163
168
  - dummy/app/mailers/.keep
164
169
  - dummy/app/models/.keep
165
170
  - dummy/app/models/concerns/.keep
166
171
  - dummy/app/models/user.rb
172
+ - dummy/app/views/.DS_Store
173
+ - dummy/app/views/dailycred/.DS_Store
174
+ - dummy/app/views/dailycred/sessions/info.html.erb
167
175
  - dummy/app/views/layouts/application.html.erb
168
176
  - dummy/bin/bundle
169
177
  - dummy/bin/rails
@@ -216,6 +224,9 @@ files:
216
224
  - lib/dailycred/user.rb
217
225
  - lib/dailycred/version.rb
218
226
  - lib/generators/USAGE
227
+ - lib/generators/dailycred/controllers_generator.rb
228
+ - lib/generators/dailycred/install_generator.rb
229
+ - lib/generators/dailycred/views_generator.rb
219
230
  - lib/generators/dailycred_generator.rb
220
231
  - lib/generators/templates/info.html.erb
221
232
  - lib/generators/templates/login.html.erb
@@ -228,7 +239,11 @@ files:
228
239
  - spec/helper_spec.rb
229
240
  - spec/support/dailycred_spec.rb
230
241
  - spec/support/shared_examples.rb
231
- - test/generator_test.rb
242
+ - test/.DS_Store
243
+ - test/generators/controllers_generator_test.rb
244
+ - test/generators/install_generator_test.rb
245
+ - test/generators/views_generator_test.rb
246
+ - test/support/common_test_helpers_test.rb
232
247
  - test/test_helper.rb
233
248
  homepage: https://github.com/dailycred/dailycred
234
249
  licenses: []
@@ -257,5 +272,10 @@ test_files:
257
272
  - spec/helper_spec.rb
258
273
  - spec/support/dailycred_spec.rb
259
274
  - spec/support/shared_examples.rb
260
- - test/generator_test.rb
275
+ - test/.DS_Store
276
+ - test/generators/controllers_generator_test.rb
277
+ - test/generators/install_generator_test.rb
278
+ - test/generators/views_generator_test.rb
279
+ - test/support/common_test_helpers_test.rb
261
280
  - test/test_helper.rb
281
+ has_rdoc:
@@ -1,31 +0,0 @@
1
- class SessionsController < ApplicationController
2
- before_filter :authenticate, :only => [:destroy]
3
- before_filter :current_user
4
- include Dailycred::Helpers
5
-
6
- # Callback Route for OAuth flow
7
- def create
8
- @user = User.find_or_create_with_omniauth auth_hash
9
- session[:user_id] = @user.id
10
- redirect_to_auth
11
- end
12
-
13
- #GET /logout
14
- def destroy
15
- session[:user_id] = nil
16
- redirect_to_unauth
17
- end
18
-
19
- def failure
20
- redirect_to_unauth notice: params[:message]
21
- end
22
-
23
- def info
24
- end
25
-
26
- private
27
-
28
- def auth_hash
29
- h = request.env['omniauth.auth']
30
- end
31
- end
@@ -1,87 +0,0 @@
1
- require 'rails/generators'
2
- require 'test/unit'
3
- # require 'mocha'
4
- require_relative "../lib/generators/dailycred_generator.rb"
5
- class GeneratorTest < Rails::Generators::TestCase
6
- tests DailycredGenerator
7
- destination File.expand_path("./tmp/myproject", File.dirname(__FILE__))
8
-
9
- setup :prepare_destination
10
-
11
- setup do
12
- # Must set before requiring generator libs.
13
- TMP_ROOT = File.dirname(__FILE__) + "/tmp" unless defined?(TMP_ROOT)
14
- PROJECT_NAME = "myproject" unless defined?(PROJECT_NAME)
15
- app_root = File.join(TMP_ROOT, PROJECT_NAME)
16
- if defined?(APP_ROOT)
17
- APP_ROOT.replace(app_root)
18
- else
19
- APP_ROOT = app_root
20
- end
21
- if defined?(RAILS_ROOT)
22
- RAILS_ROOT.replace(app_root)
23
- else
24
- RAILS_ROOT = app_root
25
- end
26
- Dir.mkdir("#{RAILS_ROOT}/config") unless File.exists?("#{RAILS_ROOT}/config")
27
- File.open("#{RAILS_ROOT}/config/routes.rb", 'w') do |f|
28
- f.puts "ActionController::Routing::Routes.draw do\n\nend"
29
- end
30
- Dir.mkdir("#{RAILS_ROOT}/app") unless File.exists?("#{RAILS_ROOT}/app")
31
- Dir.mkdir("#{RAILS_ROOT}/app/controllers") unless File.exists?("#{RAILS_ROOT}/app/controllers")
32
- File.open("#{RAILS_ROOT}/app/controllers/application_controller.rb", 'w') do |f|
33
- f.puts "class ApplicationController < ActionController::Base\n\nend"
34
- end
35
- end
36
-
37
- teardown do
38
- FileUtils.rm_rf "#{RAILS_ROOT}/app"
39
- FileUtils.rm_rf "#{RAILS_ROOT}/config"
40
- FileUtils.rm_rf "#{RAILS_ROOT}/db"
41
- end
42
-
43
- test "generator works with input" do
44
- test_generator ["aaa","bbb"]
45
- assert_credentials "aaa", "bbb"
46
- end
47
-
48
- test "generator works when skipping bootstrap" do
49
- test_generator ["aaa", "bbb", "--skip-bootstrap"]
50
- end
51
-
52
- # test "generator works with login" do
53
- # generator_class.any_instance.stubs(:get_input).returns(["localtest@dailycred.com","password"])
54
- # test_generator
55
- # assert_credentials "e92e20bf-e0a4-49b4-8a82-ff1b65d80017", "9adf81a8-ce97-4bcb-9c1f-c09f5fc7b6b8-0d1a4553-496d-450e-80fd-9e8d0552a920"
56
- # end
57
-
58
- private
59
-
60
- def test_generator args=[]
61
- run_generator args
62
- assert_file "config/initializers/omniauth.rb" do |config|
63
- assert config.include? 'Rails.configuration.DAILYCRED_CLIENT_ID ='
64
- assert config.include? 'Rails.configuration.DAILYCRED_SECRET_KEY ='
65
- end
66
-
67
- assert_file "config/routes.rb", /(#{Regexp.escape("mount Dailycred::Engine => '/auth', :as => 'dailycred_engine'")})/
68
-
69
- assert_file "app/models/user.rb" do |model|
70
- assert model.include? "acts_as_dailycred"
71
- end
72
-
73
- assert_file "app/controllers/application_controller.rb" do |controller|
74
- end
75
-
76
- assert_migration "db/migrate/create_users.rb" do |migration|
77
- end
78
- end
79
-
80
- def assert_credentials client_id, client_secret
81
- assert_file "config/initializers/omniauth.rb" do |config|
82
- assert config.include? "Rails.configuration.DAILYCRED_CLIENT_ID = \"#{client_id}\""
83
- assert config.include? "Rails.configuration.DAILYCRED_SECRET_KEY = \"#{client_secret}\""
84
- end
85
- end
86
-
87
- end