dailycred 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
- metadata.gz: ba1c79148b0ed6cfbba255f0cc520f0eee2a6bb8
4
- data.tar.gz: 635fd2685f642397c15e74c64237cdcfae8595bc
3
+ metadata.gz: 81b10aa8f02bb721ffa76a48b1e441f2db3e17df
4
+ data.tar.gz: 2fe955cbbe0da7147703bf03816a2f284ac5803b
5
5
  !binary "U0hBNTEy":
6
- metadata.gz: 276cb40be36dcbaa8c64e2753f8516945fd3e990cfd09c842305ca09aebdc5c4caa9655ce7f8cca6bae9199f182adc83623caa373d09ed333acf24f353abceb5
7
- data.tar.gz: d2da9e81f623325dd9005a14ea1ca3d1ae5a5d1ee979bca42301de13805d9f8a538c75c05030955a1b470de16159bedecfc1bc19164c7f4c21920ac16e4663aa
6
+ metadata.gz: 8d017a526d064b1df42465ec955ffe3892a57d30bdd222ffd7aa46136d30319fbacd8a6c08ff1551f05163b55917bc177f9d527b19620199326647935f896602
7
+ data.tar.gz: b73bd13c7def3a66f36d5fe6123aeb563195a9ed855f7d9a497ba2bb208e4b370c3fe4f57f9b925263fada406393d4cc21d8b9963a7a80192d8931b53581766b
data/Gemfile CHANGED
@@ -13,6 +13,11 @@ gem 'guard-rspec'
13
13
  gem "mocha", '0.12.1', :require => false
14
14
  gem 'fl-rocco'
15
15
  gem 'redcarpet', '~> 1.17'
16
- gem 'markdown'
16
+ # gem 'markdown'
17
17
  gem 'maruku'
18
- gem 'faraday'
18
+ gem 'faraday'
19
+ gem 'cucumber'
20
+ gem 'aruba'
21
+ gem 'sqlite3'
22
+ gem 'json', '~> 1.7.7'
23
+ gem 'guard-cucumber'
data/Guardfile CHANGED
@@ -13,3 +13,10 @@ guard 'rspec', :version => 2 do
13
13
  watch('spec/spec_helper.rb') { "spec" }
14
14
  end
15
15
 
16
+
17
+ # guard 'cucumber' do
18
+ # watch(%r{^features/.+\.feature$})
19
+ # watch(%r{^features/generator/.+\.feature$})
20
+ # watch(%r{^features/support/.+$}) { 'features' }
21
+ # watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
22
+ # end
data/README.md CHANGED
@@ -223,7 +223,7 @@ To specify where users should be redirected after authentication actions, setup
223
223
 
224
224
  ### Customization
225
225
 
226
- If you would like to customize this engine's `session_controller` or views, two generators are provided for you.
226
+ If you would like to customize this engine's controllers or views, two generators are provided for you.
227
227
 
228
228
  rails g dailycred:controllers
229
229
  rails g dailycred:views
data/Rakefile CHANGED
@@ -1,7 +1,10 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
3
  require 'rspec/core/rake_task'
4
+ require 'rake'
4
5
  require 'rake/testtask'
6
+ require 'rdoc/task'
7
+ # require 'tasks/rails'
5
8
 
6
9
  desc "Run specs"
7
10
  RSpec::Core::RakeTask.new do |t|
@@ -11,7 +14,7 @@ end
11
14
 
12
15
  desc "run travis"
13
16
  task :travis do
14
- ["rake spec","rake test"].each do |cmd|
17
+ ["rake spec","rake test", "cucumber"].each do |cmd|
15
18
  puts "Starting to run #{cmd}..."
16
19
  system("export DISPLAY=:99.0 && bundle exec #{cmd}")
17
20
  raise "#{cmd} failed!" unless $?.exitstatus == 0
@@ -0,0 +1,43 @@
1
+ module Dailycred
2
+ class UsersController < ApplicationController
3
+ include Dailycred::Helpers
4
+
5
+ def reset_password
6
+ if params[:user]
7
+ dailycred.reset_password(params[:user])
8
+ flash[:notice] = "Your password has been reset. See your email for further instructions."
9
+ else
10
+ flash[:notice] = "Please enter your email or password to continue."
11
+ end
12
+ redirect_to_auth
13
+ end
14
+
15
+ def login
16
+ response = dailycred.login params
17
+ if response.success?
18
+ @user = User.find_or_create_from_local_auth(response.user)
19
+ session[:user_id] = @user.id
20
+ flash[:notice] = "You have logged in successfully."
21
+ else
22
+ flash[:notice] = "There was a problem logging you in."
23
+ flash[:login_error] = response.errors["message"]
24
+ flash[:login_error_attribute] = response.errors["attribute"]
25
+ end
26
+ redirect_to_auth
27
+ end
28
+
29
+ def signup
30
+ response = dailycred.signup params
31
+ if response.success?
32
+ @user = User.find_or_create_from_local_auth(response.user)
33
+ session[:user_id] = @user.id
34
+ flash[:notice] = "You have signed up successfully."
35
+ else
36
+ flash[:notice] = "There was a problem logging you in."
37
+ flash[:signup_error] = response.errors["message"]
38
+ flash[:signup_error_attribute] = response.errors["attribute"]
39
+ end
40
+ redirect_to_auth
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,15 @@
1
+ <%= form_tag dailycred_engine.local_signup_path do %>
2
+ <% if flash[:login_error] %>
3
+ <div id="error_explanation">
4
+ <p>An error occured logging in:</p>
5
+ <h2><%= flash[:login_error] %></h2>
6
+ </div>
7
+ <% end %>
8
+ <%= label_tag :login, "Email Address" %>
9
+ <%= text_field_tag :login %>
10
+ <br>
11
+ <%= label_tag :password %>
12
+ <%= password_field_tag :password %>
13
+ <br>
14
+ <%= submit_tag "Log In" %>
15
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <%= form_tag dailycred_engine.reset_password_path do %>
2
+ <%= label_tag :user, "Email Address" %>
3
+ <%= text_field_tag :user %>
4
+ <br>
5
+ <%= submit_tag "Reset My Password" %>
6
+ <% end %>
@@ -0,0 +1,22 @@
1
+ <% get_username = false if local_assigns[:get_username].nil? %>
2
+ <%= form_tag dailycred_engine.local_signup_path do %>
3
+ <% if flash[:signup_error] %>
4
+ <div id="error_explanation">
5
+ <p>An error occured signing up:</p>
6
+ <h2><%= flash[:signup_error] %></h2>
7
+ </div>
8
+ <% end %>
9
+ <%= label_tag :email, "Email Address" %>
10
+ <%= text_field_tag :email %>
11
+ <br>
12
+ <% if get_username %>
13
+ <br>
14
+ <%= label_tag :username %>
15
+ <%= text_field_tag :username %>
16
+ <% end %>
17
+ <br>
18
+ <%= label_tag :password %>
19
+ <%= password_field_tag :password %>
20
+ <br>
21
+ <%= submit_tag "Sign Up" %>
22
+ <% end %>
@@ -1,3 +1,4 @@
1
+ <p><%= notice %><p>
1
2
  <% if current_user %>
2
3
  <p>Hello <%= current_user.email %> <br>
3
4
  <%= link_to 'Logout', dailycred_engine.logout_path %>
@@ -6,8 +7,13 @@
6
7
  <br><%= link_to 'connect with twitter', connect_user(:twitter) %>
7
8
  </p>
8
9
  <% else %>
9
- <%= link_to 'Log In', login_path() %>
10
+ <%= link_to 'Log In', login_path %>
10
11
  <br><%= link_to 'connect with facebook', connect_path(:identity_provider => :facebook) %>
11
12
  <br><%= link_to 'connect with google', connect_path(:identity_provider => :google) %>
12
13
  <br><%= link_to 'connect with twitter',connect_path(:identity_provider => :twitter) %>
14
+ <br><br><%= render partial: "reset_password" %>
15
+ <br><h3>Sign Up</h3>
16
+ <%= render partial: "signup" %>
17
+ <br><h3>Log In</h3>
18
+ <%= render partial: "login" %>
13
19
  <% end %>
@@ -4,4 +4,7 @@ Dailycred::Engine.routes.draw do
4
4
  get "/" => "dailycred/sessions#info", :as => :auth_info
5
5
  # get "/dailycred", :as => :login
6
6
  get "/failure" => "dailycred/sessions#failure"
7
+ get "/reset_password" => "dailycred/users#reset_password"
8
+ post "/" => "dailycred/users#signup", as: :local_signup
9
+ post "/login" => "dailycred/users#login", as: :local_login
7
10
  end
@@ -0,0 +1,91 @@
1
+ Feature: Creating an app with the dailycred generator
2
+
3
+ Scenario: creating an app
4
+ Given I run `rails new tmp_app`
5
+ And I cd to "tmp_app"
6
+ And a file named "Gemfile" with:
7
+ """
8
+ source "http://rubygems.org"
9
+ gem 'rails'
10
+ gem 'sqlite3'
11
+ gem 'dailycred', :path => '../../../'
12
+ group :test, :development do
13
+ gem "rspec-rails", "~> 2.0"
14
+ end
15
+ group :assets do
16
+ gem 'sass-rails', '~> 4.0.0.beta1'
17
+ gem 'coffee-rails', '~> 4.0.0.beta1'
18
+ gem 'uglifier', '>= 1.0.3'
19
+ end
20
+ gem 'jquery-rails'
21
+ gem 'turbolinks'
22
+ """
23
+ Then I successfully run `bundle install`
24
+ And I successfully run `rails generate dailycred:install`
25
+ And I successfully run `rails generate dailycred:controllers`
26
+ And I successfully run `rails generate rspec:install`
27
+ And I successfully run `rake db:migrate`
28
+ And a file named "config/initializers/omniauth.rb" with:
29
+ """
30
+ Rails.configuration.DAILYCRED_CLIENT_ID = "37a067dd-3fef-4efd-909a-38b8081c5867"
31
+ Rails.configuration.DAILYCRED_SECRET_KEY = "b622f8a7-fa92-4fe8-bb74-b5bad5db79d3-817ddff2-6fa1-4499-ae47-69ea0d4c5c44"
32
+ Rails.configuration.DAILYCRED_OPTIONS = {
33
+ :after_auth => '/auth', #after login
34
+ :after_unauth => '/' #after logout
35
+ }
36
+ """
37
+ And a file named "spec/controllers/users_controller_spec.rb" with:
38
+ """
39
+ require "spec_helper"
40
+
41
+ describe Dailycred::UsersController do
42
+ describe "GET #reset_password" do
43
+ it "responds successfully with the right parameters" do
44
+ get(:reset_password, :use_route => :auth, user: "test@test.com")
45
+ flash[:notice].should match("Your password has been reset.")
46
+ end
47
+ it "fails without the :user parameter" do
48
+ get(:reset_password, :use_route => :auth)
49
+ flash[:notice].should match("Please enter your email or password")
50
+ end
51
+ end
52
+
53
+ describe "POST login" do
54
+ it "works with the right parameters" do
55
+ post(:login, use_route: "auth", login:"test@test.com", password: "chocolate")
56
+ flash[:notice].should match("logged in successfully")
57
+ flash[:login_error].should be(nil)
58
+ assigns[:user].should_not be(nil)
59
+ assigns[:user].uid.should_not be(nil)
60
+ assigns[:user].email.should eq("test@test.com")
61
+ assigns[:user].access_tokens.should_not be(nil)
62
+ end
63
+
64
+ it "saves errors in the flash" do
65
+ post(:login, use_route: "auth", login:"test@test.com", password: "password")
66
+ flash[:notice].should match("problem")
67
+ flash[:login_error].should_not be(nil)
68
+ flash[:login_error_attribute].should_not be(nil)
69
+ end
70
+ end
71
+
72
+ describe "POST signup" do
73
+ it "works with the right parameters" do
74
+ random_email = "#{rand}email@test.com"
75
+ post(:signup, use_route: "auth", email:random_email, password: "password")
76
+ flash[:notice].should match("signed up successfully")
77
+ flash[:signup_error].should be(nil)
78
+ assigns[:user].should_not be(nil)
79
+ assigns[:user].uid.should_not be(nil)
80
+ assigns[:user].email.should eq(random_email)
81
+ end
82
+
83
+ it "saves errors in the flash" do
84
+ post(:signup, use_route: "auth", password: "password")
85
+ flash[:signup_error].should_not be(nil)
86
+ flash[:signup_error_attribute].should_not be(nil)
87
+ end
88
+ end
89
+ end
90
+ """
91
+ When I successfully run `rake spec`
@@ -0,0 +1,5 @@
1
+ require 'aruba/cucumber'
2
+
3
+ Before do
4
+ @aruba_timeout_seconds = 30
5
+ end
@@ -15,6 +15,12 @@ module ActsAsDailycred
15
15
  @user.update_from_dailycred model[:info]
16
16
  @user
17
17
  end
18
+
19
+ def find_or_create_from_local_auth(user)
20
+ @user = User.find_or_create_by(provider: "dailycred", uid: user["id"])
21
+ @user.update_from_dailycred(user)
22
+ @user
23
+ end
18
24
  end
19
25
  module InstanceMethods
20
26
  def tag tag
@@ -69,6 +69,16 @@ module Dailycred
69
69
  post "/password/api/reset", opts
70
70
  end
71
71
 
72
+ def login opts={}
73
+ opts[:pass] ||= opts[:password]
74
+ post "/user/api/signin.json", opts
75
+ end
76
+
77
+ def signup opts={}
78
+ opts[:pass] ||= opts[:password]
79
+ post "/user/api/signup.json", opts
80
+ end
81
+
72
82
  # A wildcard for making any post requests to dailycred.
73
83
  # client_id and client_secret are automatically added to the request
74
84
  #
@@ -77,7 +87,7 @@ module Dailycred
77
87
  # - @param [boolean] secure whether the client_secret should be passed. Defaults to true
78
88
  def post(url, opts, secure=true)
79
89
  opts.merge! base_opts(secure)
80
- response = get_conn.post url, opts
90
+ Dailycred::Response.new(get_conn.post url, opts)
81
91
  end
82
92
 
83
93
  private
@@ -46,7 +46,6 @@ module Dailycred
46
46
  end
47
47
 
48
48
  def redirect_to_auth opts={}
49
- p 'redirecting to auth'
50
49
  conf = Rails.configuration.DAILYCRED_OPTIONS
51
50
  path = !conf[:after_auth].nil? ? conf[:after_auth] : dailycred_engine.auth_info_path
52
51
  redirect_to path, opts
@@ -0,0 +1,33 @@
1
+ module Dailycred
2
+ class Response
3
+ require 'json'
4
+ attr_accessor :json, :body, :headers, :status
5
+
6
+ def initialize response
7
+ @body = response.body
8
+ @json = JSON.parse(@body)
9
+ @headers = response.headers
10
+ @status = response.status
11
+ end
12
+
13
+ def errors?
14
+ json["worked"] != true
15
+ end
16
+
17
+ def success?
18
+ @status == 200 && json["worked"] == true
19
+ end
20
+
21
+ def errors
22
+ begin
23
+ json["errors"][0]
24
+ rescue
25
+ nil
26
+ end
27
+ end
28
+
29
+ def user
30
+ json["user"]
31
+ end
32
+ end
33
+ end
@@ -1,3 +1,3 @@
1
1
  module Dailycred
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -1,5 +1,4 @@
1
1
  require 'rails/generators'
2
- require 'test_helper'
3
2
  module Dailycred
4
3
  module Generators
5
4
  class InstallGenerator < Rails::Generators::Base
@@ -36,31 +36,64 @@ describe Dailycred::Client do
36
36
  end
37
37
 
38
38
  it "tags a user" do
39
- json = json_response @dc.tag(@user_id, "loser")
39
+ json = @dc.tag(@user_id, "loser").json
40
40
  json["worked"].should == true
41
41
  user = json["user"]
42
42
  user["tags"].should include('loser') #will work in next push
43
43
  end
44
44
 
45
45
  it "untags a user" do
46
- json = json_response @dc.untag(@user_id, "loser")
46
+ json = @dc.untag(@user_id, "loser").json
47
47
  json["worked"].should == true
48
48
  user = json["user"]
49
49
  user["tags"].should == nil #will work in next push
50
50
  end
51
51
 
52
52
  it "fires an event" do
53
- json = json_response @dc.event(@user_id, "became a loser")
53
+ json = @dc.event(@user_id, "became a loser").json
54
54
  json["worked"].should == true
55
55
  end
56
56
 
57
57
  it "resets a password" do
58
- json = json_response @dc.reset_password("useruseruseruser@gmail.com")
58
+ json = @dc.reset_password("useruseruseruser@gmail.com").json
59
59
  json["worked"].should == true
60
60
  end
61
61
 
62
+ describe "#login" do
63
+ it "logs in successfully" do
64
+ response = @dc.login(login: "test@test.com", password: "password")
65
+ response.success?.should eq(true)
66
+ response.user["email"].should eq("test@test.com")
67
+ response.errors.should be(nil)
68
+ end
69
+
70
+ it "works with :pass parameter too" do
71
+ response = @dc.login(login: "test@test.com", pass: "password")
72
+ response.success?.should eq(true)
73
+ response.user["email"].should eq("test@test.com")
74
+ response.errors.should be(nil)
75
+ end
76
+
77
+ it "fails with wrong credentials" do
78
+ response = @dc.login(login: "test@test.com", password: "wrongpass")
79
+ response.success?.should eq(false)
80
+ response.errors["attribute"].should eq("form")
81
+ response.errors["message"].should_not be(nil)
82
+ end
83
+ end
84
+
85
+ describe "#signup" do
86
+ it "works with right parameters" do
87
+ random_email = "#{rand}test@test.com"
88
+ response = @dc.signup(email: random_email, password: "password")
89
+ response.success?.should eq(true)
90
+ response.user["email"].should eq(random_email)
91
+ end
92
+ end
93
+
94
+
62
95
  # it "changes a password" do
63
- # json = json_response @dc.changePass("0c19c355-2a71-4c8e-805e-f7a6087ea84c", "wrongPass", "newPass")
96
+ # json = @dc.changePass("0c19c355-2a71-4c8e-805e-f7a6087ea84c", "wrongPass", "newPass").json
64
97
  # json["worked"].should == false
65
98
  # json["message"].should != nil
66
99
  # end
@@ -8,6 +8,7 @@ class ViewsGeneratorTest < Rails::Generators::TestCase
8
8
  test "creates correct controller files" do
9
9
  run_generator
10
10
  assert_file "app/controllers/dailycred/sessions_controller.rb"
11
+ assert_file "app/controllers/dailycred/users_controller.rb"
11
12
  end
12
13
 
13
14
  end
@@ -8,6 +8,9 @@ class ControllersGeneratorTest < Rails::Generators::TestCase
8
8
  test "creates correct view files" do
9
9
  run_generator
10
10
  assert_file "app/views/dailycred/sessions/info.html.erb"
11
+ assert_file "app/views/dailycred/sessions/_login.html.erb"
12
+ assert_file "app/views/dailycred/sessions/_signup.html.erb"
13
+ assert_file "app/views/dailycred/sessions/_reset_password.html.erb"
11
14
  end
12
15
 
13
16
  end
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.3.0
4
+ version: 0.3.1
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-05-02 00:00:00.000000000 Z
11
+ date: 2013-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth
@@ -55,8 +55,12 @@ files:
55
55
  - Rakefile
56
56
  - app/controllers/.DS_Store
57
57
  - app/controllers/dailycred/sessions_controller.rb
58
+ - app/controllers/dailycred/users_controller.rb
58
59
  - app/views/.DS_Store
59
60
  - app/views/dailycred/.DS_Store
61
+ - app/views/dailycred/sessions/_login.html.erb
62
+ - app/views/dailycred/sessions/_reset_password.html.erb
63
+ - app/views/dailycred/sessions/_signup.html.erb
60
64
  - app/views/dailycred/sessions/info.html.erb
61
65
  - config/routes.rb
62
66
  - dailycred.gemspec
@@ -214,12 +218,15 @@ files:
214
218
  - dummy/test/test_helper.rb
215
219
  - dummy/vendor/assets/javascripts/.keep
216
220
  - dummy/vendor/assets/stylesheets/.keep
221
+ - features/generator/generator.feature
222
+ - features/support/env.rb
217
223
  - lib/dailycred.rb
218
224
  - lib/dailycred/acts_as_dailycred.rb
219
225
  - lib/dailycred/client.rb
220
226
  - lib/dailycred/engine.rb
221
227
  - lib/dailycred/helper.rb
222
228
  - lib/dailycred/middleware.rb
229
+ - lib/dailycred/response.rb
223
230
  - lib/dailycred/tests_helper.rb
224
231
  - lib/dailycred/user.rb
225
232
  - lib/dailycred/version.rb
@@ -269,6 +276,8 @@ signing_key:
269
276
  specification_version: 4
270
277
  summary: ''
271
278
  test_files:
279
+ - features/generator/generator.feature
280
+ - features/support/env.rb
272
281
  - spec/helper_spec.rb
273
282
  - spec/support/dailycred_spec.rb
274
283
  - spec/support/shared_examples.rb