dailycred 0.1.8 → 0.1.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. data/.gitignore +0 -4
  2. data/Gemfile +3 -15
  3. data/README.md +34 -190
  4. data/Rakefile +0 -41
  5. data/dailycred.gemspec +5 -7
  6. data/lib/dailycred.rb +86 -1
  7. data/lib/generators/dailycred_generator.rb +44 -92
  8. data/lib/generators/templates/info.html.erb +1 -1
  9. data/lib/generators/templates/migration_create_user.rb +10 -54
  10. data/lib/generators/templates/omniauth.rb +17 -6
  11. data/lib/generators/templates/sessions_controller.rb +2 -8
  12. data/lib/generators/templates/user.rb +23 -1
  13. data/lib/middleware/middleware.rb +57 -0
  14. data/lib/omniauth/strategies/dailycred.rb +62 -0
  15. data/lib/omniauth-dailycred/version.rb +5 -0
  16. data/spec/omniauth/strategies/dailycred_spec.rb +22 -0
  17. data/spec/{helper_spec.rb → spec_helper.rb} +3 -3
  18. metadata +23 -107
  19. checksums.yaml +0 -7
  20. data/.travis.yml +0 -3
  21. data/Guardfile +0 -15
  22. data/app/controllers/sessions_controller.rb +0 -31
  23. data/app/views/sessions/info.html.erb +0 -13
  24. data/config/routes.rb +0 -7
  25. data/docs/lib/dailycred/acts_as_dailycred.html +0 -42
  26. data/docs/lib/dailycred/client.html +0 -214
  27. data/docs/lib/dailycred/engine.html +0 -112
  28. data/docs/lib/dailycred/helper.html +0 -125
  29. data/docs/lib/dailycred/middleware.html +0 -42
  30. data/docs/lib/dailycred/tests_helper.html +0 -42
  31. data/docs/lib/dailycred/user.html +0 -133
  32. data/docs/lib/dailycred.html +0 -42
  33. data/docs/lib/generators/dailycred_generator.html +0 -42
  34. data/docs/lib/generators/templates/migration_create_user.html +0 -39
  35. data/docs/lib/generators/templates/omniauth.html +0 -71
  36. data/docs/lib/generators/templates/sessions_controller.html +0 -96
  37. data/docs/lib/generators/templates/user.html +0 -42
  38. data/docs/lib/middleware/middleware.html +0 -38
  39. data/docs/lib/omniauth/strategies/dailycred.html +0 -199
  40. data/docs/lib/omniauth-dailycred/version.html +0 -38
  41. data/docs/lib/user/user.html +0 -129
  42. data/dummy/.gitignore +0 -16
  43. data/dummy/Gemfile +0 -40
  44. data/dummy/README.rdoc +0 -28
  45. data/dummy/Rakefile +0 -6
  46. data/dummy/app/assets/images/rails.png +0 -0
  47. data/dummy/app/assets/javascripts/application.js +0 -16
  48. data/dummy/app/assets/stylesheets/application.css +0 -13
  49. data/dummy/app/controllers/application_controller.rb +0 -17
  50. data/dummy/app/controllers/concerns/.keep +0 -0
  51. data/dummy/app/helpers/application_helper.rb +0 -2
  52. data/dummy/app/mailers/.keep +0 -0
  53. data/dummy/app/models/.keep +0 -0
  54. data/dummy/app/models/concerns/.keep +0 -0
  55. data/dummy/app/models/user.rb +0 -3
  56. data/dummy/app/views/layouts/application.html.erb +0 -14
  57. data/dummy/bin/bundle +0 -3
  58. data/dummy/bin/rails +0 -4
  59. data/dummy/bin/rake +0 -4
  60. data/dummy/config/application.rb +0 -22
  61. data/dummy/config/boot.rb +0 -4
  62. data/dummy/config/database.yml +0 -25
  63. data/dummy/config/environment.rb +0 -5
  64. data/dummy/config/environments/development.rb +0 -27
  65. data/dummy/config/environments/production.rb +0 -80
  66. data/dummy/config/environments/test.rb +0 -36
  67. data/dummy/config/initializers/backtrace_silencers.rb +0 -7
  68. data/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  69. data/dummy/config/initializers/inflections.rb +0 -16
  70. data/dummy/config/initializers/mime_types.rb +0 -5
  71. data/dummy/config/initializers/omniauth.rb +0 -9
  72. data/dummy/config/initializers/secret_token.rb +0 -12
  73. data/dummy/config/initializers/session_store.rb +0 -3
  74. data/dummy/config/initializers/wrap_parameters.rb +0 -14
  75. data/dummy/config/locales/en.yml +0 -23
  76. data/dummy/config/routes.rb +0 -50
  77. data/dummy/config.ru +0 -4
  78. data/dummy/db/migrate/20130417131939_create_users.rb +0 -64
  79. data/dummy/db/schema.rb +0 -36
  80. data/dummy/db/seeds.rb +0 -7
  81. data/dummy/lib/assets/.keep +0 -0
  82. data/dummy/lib/tasks/.keep +0 -0
  83. data/dummy/log/.keep +0 -0
  84. data/dummy/public/404.html +0 -27
  85. data/dummy/public/422.html +0 -26
  86. data/dummy/public/500.html +0 -26
  87. data/dummy/public/favicon.ico +0 -0
  88. data/dummy/public/robots.txt +0 -5
  89. data/dummy/test/controllers/.keep +0 -0
  90. data/dummy/test/fixtures/.keep +0 -0
  91. data/dummy/test/helpers/.keep +0 -0
  92. data/dummy/test/integration/.keep +0 -0
  93. data/dummy/test/mailers/.keep +0 -0
  94. data/dummy/test/models/.keep +0 -0
  95. data/dummy/test/test_helper.rb +0 -15
  96. data/dummy/vendor/assets/javascripts/.keep +0 -0
  97. data/dummy/vendor/assets/stylesheets/.keep +0 -0
  98. data/lib/dailycred/acts_as_dailycred.rb +0 -74
  99. data/lib/dailycred/client.rb +0 -106
  100. data/lib/dailycred/engine.rb +0 -53
  101. data/lib/dailycred/helper.rb +0 -61
  102. data/lib/dailycred/middleware.rb +0 -70
  103. data/lib/dailycred/tests_helper.rb +0 -5
  104. data/lib/dailycred/user.rb +0 -63
  105. data/lib/dailycred/version.rb +0 -3
  106. data/lib/generators/templates/login.html.erb +0 -13
  107. data/script/download_info.rb +0 -11
  108. data/spec/support/dailycred_spec.rb +0 -72
  109. data/spec/support/shared_examples.rb +0 -40
  110. data/test/generator_test.rb +0 -83
  111. data/test/test_helper.rb +0 -6
@@ -1,106 +0,0 @@
1
- module Dailycred
2
- class Client
3
- require 'faraday'
4
- attr_accessor :client_id, :secret_key, :options, :url
5
-
6
- URL = "https://www.dailycred.com"
7
-
8
- ROUTES = {
9
- :signup => "/user/api/signup.json",
10
- :login => "/user/api/signin.json"
11
- }
12
-
13
- # Initializes a dailycred object
14
- #
15
- # - @param [String] client\_id the client's daiycred client id
16
- # - @param [String] secret\_key the clients secret key
17
- # - @param [Hash] opts a hash of options
18
- def initialize(client_id, secret_key="", opts={})
19
- @client_id = client_id
20
- @secret_key = secret_key
21
- @options = opts
22
- opts[:client_options] ||= {}
23
- @url = opts[:client_options][:site] || Dailycred::Client::URL
24
- end
25
-
26
- # Generates a Dailycred event
27
- #
28
- # - @param [String] user_id the user's dailycred user id
29
- # - @param [String] key the name of the event type
30
- # - @param [String] val the value of the event (optional)
31
- def event(user_id, key, val="")
32
- opts = {
33
- :key => key,
34
- :valuestring => val,
35
- :user_id => user_id
36
- }
37
- post "/admin/api/customevent.json", opts
38
- end
39
-
40
- # Tag a user in dailycred
41
- #
42
- # - @param [String] user_id the user's dailycred user id
43
- # - @param [String] tag the desired tag to add
44
- def tag(user_id, tag)
45
- opts = {
46
- :user_id => user_id,
47
- :tag => tag
48
- }
49
- post "/admin/api/user/tag.json", opts
50
- end
51
-
52
- # Untag a user in dailycred
53
- # (see #tag)
54
- def untag(user_id, tag)
55
- opts = {
56
- :user_id => user_id,
57
- :tag => tag
58
- }
59
- post "/admin/api/user/untag.json", opts
60
- end
61
-
62
- # Send a reset password email
63
- #
64
- # - @param [string] user the user's email or username
65
- def reset_password(user)
66
- opts = {
67
- :user => user
68
- }
69
- post "/password/api/reset", opts
70
- end
71
-
72
- # A wildcard for making any post requests to dailycred.
73
- # client_id and client_secret are automatically added to the request
74
- #
75
- # - @param [string] url
76
- # - @param [hash] opts
77
- # - @param [boolean] secure whether the client_secret should be passed. Defaults to true
78
- def post(url, opts, secure=true)
79
- opts.merge! base_opts(secure)
80
- response = get_conn.post url, opts
81
- end
82
-
83
- private
84
-
85
- def ssl_opts
86
- opts = {}
87
- if @options[:client_options] && @options[:client_options][:ssl]
88
- opts[:ssl] = @options[:client_options][:ssl]
89
- elsif Rails.configuration.respond_to? "DAILYCRED_OPTIONS"
90
- opts[:ssl] = Rails.configuration.DAILYCRED_OPTIONS[:client_options][:ssl]
91
- end
92
- opts
93
- end
94
-
95
- def base_opts secure=true
96
- opts = {:client_id => @client_id}
97
- opts[:client_secret] = @secret_key if secure
98
- opts
99
- end
100
-
101
- def get_conn
102
- Faraday::Connection.new @url, ssl_opts
103
- end
104
- end
105
-
106
- end
@@ -1,53 +0,0 @@
1
- require 'rails'
2
- module Dailycred
3
-
4
- class Engine < Rails::Engine
5
-
6
- initializer 'dailycred.setup', :after=>"dailycred" do |app|
7
- conf = Rails.configuration# alias for configuration
8
- if conf.respond_to? 'DAILYCRED_CLIENT_ID'
9
- id = conf.DAILYCRED_CLIENT_ID
10
- secret = conf.DAILYCRED_SECRET_KEY
11
-
12
- # setup omniauth options, can be overridden. ex:
13
- # Rails.application.DAILYCRED_OPTIONS = {
14
- # :client_options => {
15
- # :site => 'https://www.dailycred.com',
16
- # :authorize_url => '/connect',
17
- # :token_url => '/oauth/access_token'
18
- # }
19
- # }
20
- if conf.respond_to? 'DAILYCRED_OPTIONS'
21
- opts = conf.DAILYCRED_OPTIONS
22
- opts[:client_options] ||= {}
23
- opts[:client_options][:ssl] = {}
24
- else
25
- opts = {:client_options => {:ssl => {}}}
26
- end
27
-
28
- if File.exists?('/etc/ssl/certs')
29
- opts[:client_options][:ssl][:ca_path] = '/etc/ssl/certs'
30
- end
31
- if File.exists?('/opt/local/share/curl/curl-ca-bundle.crt')
32
- opts[:client_options][:ssl][:ca_file] = '/opt/local/share/curl/curl-ca-bundle.crt'
33
- end
34
-
35
- conf.DAILYCRED_OPTIONS = opts
36
-
37
- Rails.application.config.middleware.use OmniAuth::Builder do
38
- provider :dailycred, id, secret, opts
39
- end
40
- opts[:middleware] ||= {}
41
- Rails.application.config.middleware.use "Dailycred::Middleware", id, opts[:middleware]
42
-
43
- ActiveSupport.on_load(:action_controller) do
44
- include Dailycred::Helpers
45
- helper Dailycred::Helpers
46
- end
47
- end
48
- end
49
-
50
-
51
- end
52
-
53
- end
@@ -1,61 +0,0 @@
1
- module Dailycred
2
- module Helpers
3
-
4
- # use as a before_filter to only allow signed in users
5
- # example:
6
- # before_filter :authenticate
7
- def authenticate
8
- redirect_to_unauth unless current_user
9
- end
10
-
11
- # helper method for getting an instance of dailycred
12
- # example:
13
- # dailycred.tagUser "user_id", "tag"
14
- #
15
- # for more documentation, visit https://www.dailycred.com/api/ruby
16
- def dailycred
17
- config = Rails.configuration
18
- @dailycred ||= Dailycred::Client.new(config.DAILYCRED_CLIENT_ID, config.DAILYCRED_SECRET_KEY, config.DAILYCRED_OPTIONS)
19
- end
20
-
21
- # when making oauth calls, we may need to redirect to our oauth callback url
22
- # make sure we have the correct state passed back and forth
23
- def set_state
24
- @state = session["omniauth.state"] = SecureRandom.hex(24)
25
- end
26
-
27
- def login_path(params={})
28
- connect_path params
29
- end
30
-
31
- def connect_path(params={})
32
- url = "#{request.protocol}#{request.host_with_port}/auth/dailycred"
33
- params_array = []
34
- params.each do |k,v|
35
- params_array << "#{k}=#{v.to_s}"
36
- end
37
- url += "?" if params_array.size > 0
38
- url += params_array.join("&")
39
- end
40
-
41
- def connect_user provider, user=nil
42
- if user.nil?
43
- user = current_user
44
- end
45
- connect_path(:access_token => user.token, :identity_provider => provider)
46
- end
47
-
48
- def redirect_to_auth opts={}
49
- p 'redirecting to auth'
50
- conf = Rails.configuration.DAILYCRED_OPTIONS
51
- path = !conf[:after_auth].nil? ? conf[:after_auth] : dailycred_engine.auth_info_path
52
- redirect_to path, opts
53
- end
54
-
55
- def redirect_to_unauth opts = {}
56
- conf = Rails.configuration.DAILYCRED_OPTIONS
57
- path = !conf[:after_unauth].nil? ? conf[:after_unauth] : dailycred_engine.auth_info_path
58
- redirect_to path, opts
59
- end
60
- end
61
- end
@@ -1,70 +0,0 @@
1
- module Dailycred
2
- class Middleware
3
- attr_accessor :client_id
4
-
5
- def initialize(app, client_id, opts={})
6
- @opts = opts
7
- @opts[:url] ||= "https://www.dailycred.com"
8
- @opts[:modal] ||= false
9
- @opts[:sdk] ||= false
10
- @opts[:triggers] ||= []
11
- @app = app
12
- @client_id = client_id
13
- end
14
-
15
- def call(env)
16
- @env = env
17
- @status, @headers, @response = @app.call(env)
18
- if @headers["Content-Type"] =~ /text\/html|application\/xhtml\+xml/
19
- body = ""
20
- @response.each { |part| body << part }
21
- index = body.rindex("</body>")
22
- if index
23
- body.insert(index, render_dailycred_scripts)
24
- @headers["Content-Length"] = body.length.to_s
25
- @response = [body]
26
- end
27
- end
28
- @env['rack.session']['omniauth.state'] ||= SecureRandom.hex(24)
29
- [@status, @headers, @response]
30
- end
31
-
32
- private
33
-
34
- def render_dailycred_scripts
35
- str =<<-EOT
36
- <!-- dailycred -->
37
- #{'<script src="https://login.persona.org/include.js"></script>' if @opts[:persona_audience]}
38
- <script type="text/javascript">
39
- (function() {
40
- var dc, url;
41
- window.dc_opts = {
42
- clientId: "#{@client_id}",
43
- home: "#{@opts[:url]}",
44
- state: "#{@env['rack.session']['omniauth.state']}"
45
- #{", type: \"#{@status.to_s}\"" if @status == 500 || @status == 400}
46
- #{", personaAudience: \"#{@opts[:persona_audience]}\"" if @opts[:persona_audience]}
47
- };
48
- dc = document.createElement("script");
49
- url = dc_opts.home + "/public/js/cred.coffee";
50
- dc.src = url;
51
- document.body.appendChild(dc);
52
- }).call(this);
53
- </script>
54
- EOT
55
- str2 =<<-EOT
56
- <script src="https://s3.amazonaws.com/file.dailycred.com/js/dailycred.js"></script>
57
- <script>
58
- DC.init({
59
- "showModal" : #{@opts[:modal]}
60
- #{',"modal":{"triggers":'+@opts[:triggers].to_s+'}' if @opts[:modal]}
61
- });
62
- </script>
63
- EOT
64
- str += str2 if @opts[:sdk]
65
- str += "\n<!-- end dailycred -->"
66
- str
67
- end
68
-
69
- end
70
- end
@@ -1,5 +0,0 @@
1
- module Dailycred
2
- module TestHelper
3
-
4
- end
5
- end
@@ -1,63 +0,0 @@
1
- # module Dailycred
2
- # class User
3
- # include ActiveModel::Validations
4
- # include ActiveModel::Serialization
5
-
6
- # validates_presence_of :email, :pass
7
-
8
- # attr_accessor :client, :email, :pass, :authorized
9
-
10
- # def initialize client, user = {}
11
- # self.client = client
12
- # self.authorized = false
13
- # user.each do |k,v|
14
- # self[k] = v if self.respond_to(k)
15
- # end
16
- # end
17
-
18
- # def login
19
- # if !self.valid?
20
- # #it didn't work already, return false
21
- # return false
22
- # end
23
-
24
- # response = JSON.parse client.login(self.to_hash)
25
- # err_parser response
26
-
27
- # return false if !self.valid?
28
- # true
29
- # end
30
-
31
- # def to_hash
32
- # {
33
- # :email => self.email,
34
- # :pass => self.pass
35
- # }
36
- # end
37
-
38
- # private
39
-
40
- # #response is a hash, which is
41
- # #a json-parsed http response body
42
- # def err_parser response
43
- # if !response["worked"]
44
- # self.authorized = false
45
- # response["errors"].each do |err|
46
- # attrib = err["attribute"]
47
- # message = err["message"]
48
- # if attrib == "form"
49
- # self.errors.add_to_base message
50
- # else
51
- # if attrib == "user"
52
- # self.errors.add :email, message
53
- # elsif self.respond_to attrib
54
- # self.errors.add attrib, message
55
- # end
56
- # end
57
- # end
58
- # end
59
- # end
60
-
61
- # end
62
-
63
- # end
@@ -1,3 +0,0 @@
1
- module Dailycred
2
- VERSION = "0.1.8"
3
- end
@@ -1,13 +0,0 @@
1
- <%= form_for(@user) do |f| %>
2
- <p>
3
- <%= f.label :email %>
4
- <%= f.text_field :email%>
5
- </p>
6
- <p>
7
- <%= f.label :password %>
8
- <%= f.password_field :password %>
9
- </p>
10
- <p>
11
- <%= f.submit "Log in" %>
12
- </p>
13
- <% end %>
@@ -1,11 +0,0 @@
1
- require 'gems'
2
- require 'pp'
3
- total = 0
4
- Gems.versions('dailycred').reverse.each_with_index do |v,i|
5
- p "version: #{v['number']}"
6
- p "downloads: #{v['downloads_count']}"
7
- total += v['downloads_count']
8
- p "total: #{total}"
9
- p "release date: #{Date.parse(v['built_at']).to_time.strftime('%m/%d/%Y')}"
10
- p "----------"
11
- end
@@ -1,72 +0,0 @@
1
- require 'json'
2
- require 'pp'
3
- require 'dailycred'
4
- describe Dailycred::Client do
5
- subject do
6
-
7
- end
8
-
9
- before(:each) do
10
- site = "https://www.dailycred.com"
11
- client_id = "f1fd998c-bc48-4e1b-bc88-98f9373ba60f"
12
- secret = "6925d89e-d04d-469e-8fc9-3782af57bc29-c2340f1e-25a0-40af-b638-7429947a6cd7"
13
- @user_id = "0c19c355-2a71-4c8e-805e-f7a6087ea84c"
14
-
15
- # dev settings
16
- # site = "http://localhost:9000"
17
- # client_id = "4337ed55-aaca-4e38-8824-6c016c59dd5b"
18
- # secret = "34f2ecc3-f955-4292-9747-39b876d91d8b-a4f7ad8e-f8a4-4573-b23d-686f6e28a820"
19
- # @user_id = "97a85558-c5a6-47de-ab89-4e7de02c99bd"
20
-
21
- dc_options = { :client_options => {
22
- :site => site,
23
- :authorize_url => '/oauth/authorize',
24
- :token_url => '/oauth/access_token'
25
- } }
26
-
27
- if File.exists?('/etc/ssl/certs')
28
- dc_options[:client_options][:ssl] = { :ca_path => '/etc/ssl/certs'}
29
- end
30
-
31
- if File.exists?('/opt/local/share/curl/curl-ca-bundle.crt')
32
- dc_options[:client_options][:ssl] = { :ca_file => '/opt/local/share/curl/curl-ca-bundle.crt' }
33
- end
34
-
35
- @dc = Dailycred::Client.new client_id, secret, dc_options
36
- end
37
-
38
- it "tags a user" do
39
- json = json_response @dc.tag(@user_id, "loser")
40
- json["worked"].should == true
41
- user = json["user"]
42
- user["tags"].should include('loser') #will work in next push
43
- end
44
-
45
- it "untags a user" do
46
- json = json_response @dc.untag(@user_id, "loser")
47
- json["worked"].should == true
48
- user = json["user"]
49
- user["tags"].should == nil #will work in next push
50
- end
51
-
52
- it "fires an event" do
53
- json = json_response @dc.event(@user_id, "became a loser")
54
- json["worked"].should == true
55
- end
56
-
57
- it "resets a password" do
58
- json = json_response @dc.reset_password("useruseruseruser@gmail.com")
59
- json["worked"].should == true
60
- end
61
-
62
- # it "changes a password" do
63
- # json = json_response @dc.changePass("0c19c355-2a71-4c8e-805e-f7a6087ea84c", "wrongPass", "newPass")
64
- # json["worked"].should == false
65
- # json["message"].should != nil
66
- # end
67
-
68
-
69
- def json_response response
70
- JSON.parse response.body
71
- end
72
- end
@@ -1,40 +0,0 @@
1
- # NOTE it would be useful if this lived in omniauth-oauth2 eventually
2
- # Thanks to Josh Ellithorpe for this file -Will
3
-
4
- shared_examples 'an oauth2 strategy' do
5
- describe '#client' do
6
- it 'should be initialized with symbolized client_options' do
7
- @options = { :client_options => { 'authorize_url' => 'https://example.com' } }
8
- subject.client.options[:authorize_url].should == 'https://example.com'
9
- end
10
- end
11
-
12
- describe '#authorize_params' do
13
- # it 'should include any authorize params passed in the :authorize_params option' do
14
- # @options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } }
15
- # p subject.authorize_params
16
- # subject.authorize_params['foo'].should eq('bar')
17
- # subject.authorize_params['baz'].should eq('zip')
18
- # end
19
-
20
- it 'should include top-level options that are marked as :authorize_options' do
21
- @options = { :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
22
- subject.authorize_params['scope'].should eq('bar')
23
- subject.authorize_params['foo'].should eq('baz')
24
- end
25
- end
26
-
27
- describe '#token_params' do
28
- it 'should include any token params passed in the :token_params option' do
29
- @options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
30
- subject.token_params['foo'].should eq('bar')
31
- subject.token_params['baz'].should eq('zip')
32
- end
33
-
34
- it 'should include top-level options that are marked as :token_options' do
35
- @options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
36
- subject.token_params['scope'].should eq('bar')
37
- subject.token_params['foo'].should eq('baz')
38
- end
39
- end
40
- end
@@ -1,83 +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 with login" do
49
- # generator_class.any_instance.stubs(:get_input).returns(["localtest@dailycred.com","password"])
50
- # test_generator
51
- # assert_credentials "e92e20bf-e0a4-49b4-8a82-ff1b65d80017", "9adf81a8-ce97-4bcb-9c1f-c09f5fc7b6b8-0d1a4553-496d-450e-80fd-9e8d0552a920"
52
- # end
53
-
54
- private
55
-
56
- def test_generator args=[]
57
- run_generator args
58
- assert_file "config/initializers/omniauth.rb" do |config|
59
- assert config.include? 'Rails.configuration.DAILYCRED_CLIENT_ID ='
60
- assert config.include? 'Rails.configuration.DAILYCRED_SECRET_KEY ='
61
- end
62
-
63
- assert_file "config/routes.rb", /(#{Regexp.escape("mount Dailycred::Engine => '/auth', :as => 'dailycred_engine'")})/
64
-
65
- assert_file "app/models/user.rb" do |model|
66
- assert model.include? "acts_as_dailycred"
67
- end
68
-
69
- assert_file "app/controllers/application_controller.rb" do |controller|
70
- end
71
-
72
- assert_migration "db/migrate/create_users.rb" do |migration|
73
- end
74
- end
75
-
76
- def assert_credentials client_id, client_secret
77
- assert_file "config/initializers/omniauth.rb" do |config|
78
- assert config.include? "Rails.configuration.DAILYCRED_CLIENT_ID = \"#{client_id}\""
79
- assert config.include? "Rails.configuration.DAILYCRED_SECRET_KEY = \"#{client_secret}\""
80
- end
81
- end
82
-
83
- end
data/test/test_helper.rb DELETED
@@ -1,6 +0,0 @@
1
- require 'test/unit'
2
- # require 'mocha/setup'
3
-
4
-
5
- require_relative './generator_test.rb'
6
-