socialite 0.0.1.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. data/.autotest +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +10 -0
  5. data/.yardopts +8 -0
  6. data/Gemfile +8 -0
  7. data/Gemfile.lock +208 -0
  8. data/LICENSE +176 -0
  9. data/README.md +63 -0
  10. data/Rakefile +34 -0
  11. data/app/assets/images/socialite/.gitkeep +0 -0
  12. data/app/assets/javascripts/socialite/.gitkeep +0 -0
  13. data/app/assets/stylesheets/socialite/socialite.css +40 -0
  14. data/app/assets/stylesheets/socialite.css +7 -0
  15. data/app/controllers/socialite/identities_controller.rb +53 -0
  16. data/app/controllers/socialite/session_controller.rb +28 -0
  17. data/app/controllers/socialite/user_controller.rb +39 -0
  18. data/app/helpers/socialite/authentication_helper.rb +15 -0
  19. data/app/models/socialite/facebook_identity.rb +7 -0
  20. data/app/models/socialite/identity.rb +6 -0
  21. data/app/models/socialite/user.rb +42 -0
  22. data/app/views/socialite/identities/_identities.html.haml +14 -0
  23. data/app/views/socialite/session/new.html.haml +14 -0
  24. data/app/views/socialite/user/_form.html.haml +13 -0
  25. data/app/views/socialite/user/edit.html.haml +1 -0
  26. data/app/views/socialite/user/show.html.haml +16 -0
  27. data/config/initializers/simple_form.rb +90 -0
  28. data/config/locales/simple_form.en.yml +23 -0
  29. data/config/routes.rb +10 -0
  30. data/db/migrate/20110914215410_create_users.rb +14 -0
  31. data/db/migrate/20110925224222_create_identities.rb +26 -0
  32. data/db/migrate/20110926005551_create_facebook_identities.rb +12 -0
  33. data/features/authentication/facebook_signin.feature +5 -0
  34. data/features/authentication/twitter_signin.feature +5 -0
  35. data/features/identities/facebook_management.feature +14 -0
  36. data/features/identities/twitter_management.feature +7 -0
  37. data/features/registration/facebook_signup.feature +10 -0
  38. data/features/registration/twitter_signup.feature +0 -0
  39. data/features/step_definitions/authentication_steps.rb +31 -0
  40. data/features/step_definitions/common_steps.rb +13 -0
  41. data/features/step_definitions/identity_steps.rb +5 -0
  42. data/features/step_definitions/web_steps.rb +254 -0
  43. data/features/support/env.rb +58 -0
  44. data/features/support/hooks.rb +3 -0
  45. data/features/support/omniauth.rb +31 -0
  46. data/features/support/paths.rb +34 -0
  47. data/features/support/selectors.rb +39 -0
  48. data/lib/socialite/api_wrappers/facebook.rb +67 -0
  49. data/lib/socialite/api_wrappers/twitter.rb +19 -0
  50. data/lib/socialite/base_identity.rb +96 -0
  51. data/lib/socialite/controller_support.rb +136 -0
  52. data/lib/socialite/engine.rb +32 -0
  53. data/lib/socialite/service_config.rb +14 -0
  54. data/lib/socialite/version.rb +3 -0
  55. data/lib/socialite.rb +37 -0
  56. data/lib/tasks/.gitkeep +0 -0
  57. data/lib/tasks/cucumber.rake +65 -0
  58. data/lib/tasks/socialite_tasks.rake +4 -0
  59. data/script/cucumber +10 -0
  60. data/script/rails +6 -0
  61. data/socialite.gemspec +39 -0
  62. data/spec/dummy/Rakefile +7 -0
  63. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  64. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  65. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  66. data/spec/dummy/app/controllers/home_controller.rb +11 -0
  67. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  68. data/spec/dummy/app/views/home/index.html.haml +12 -0
  69. data/spec/dummy/app/views/home/show.html.haml +6 -0
  70. data/spec/dummy/app/views/layouts/application.html.erb +18 -0
  71. data/spec/dummy/config/application.rb +48 -0
  72. data/spec/dummy/config/boot.rb +20 -0
  73. data/spec/dummy/config/database.yml +9 -0
  74. data/spec/dummy/config/environment.rb +5 -0
  75. data/spec/dummy/config/environments/development.rb +30 -0
  76. data/spec/dummy/config/environments/production.rb +60 -0
  77. data/spec/dummy/config/environments/test.rb +42 -0
  78. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  79. data/spec/dummy/config/initializers/inflections.rb +10 -0
  80. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  81. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  82. data/spec/dummy/config/initializers/session_store.rb +8 -0
  83. data/spec/dummy/config/initializers/socialite.rb +6 -0
  84. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  85. data/spec/dummy/config/locales/en.yml +5 -0
  86. data/spec/dummy/config/routes.rb +11 -0
  87. data/spec/dummy/config.ru +4 -0
  88. data/spec/dummy/db/schema.rb +43 -0
  89. data/spec/dummy/public/404.html +26 -0
  90. data/spec/dummy/public/422.html +26 -0
  91. data/spec/dummy/public/500.html +26 -0
  92. data/spec/dummy/public/favicon.ico +0 -0
  93. data/spec/dummy/script/rails +6 -0
  94. data/spec/factories/facebook.rb +5 -0
  95. data/spec/factories/identity.rb +9 -0
  96. data/spec/factories/twitter.rb +6 -0
  97. data/spec/factories/user.rb +16 -0
  98. data/spec/models/facebook_spec.rb +28 -0
  99. data/spec/models/identity_spec.rb +9 -0
  100. data/spec/models/user_spec.rb +27 -0
  101. data/spec/spec_helper.rb +29 -0
  102. data/spec/support/.gitkeep +0 -0
  103. data/spec/support/database_loader.rb +13 -0
  104. data/spec/support/databases.yml +14 -0
  105. data/spec/support/identity_shared_example.rb +67 -0
  106. metadata +409 -0
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,10 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Dummy::Application.config.secret_token = '4b232d389ba2c60db3997624e83822d79577a385e82149d0a277baa7e0e8a9898fdb21b3264f9be0bd0154e7e792e4cdf52a7c0f36e93042cb247ae72b0c61e6'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # Dummy::Application.config.session_store :active_record_store
@@ -0,0 +1,6 @@
1
+ require 'socialite'
2
+
3
+ Socialite.setup do |config|
4
+ config.facebook '281326728563029', '48f0828a7e5530c8ae0e2c32dd6c6cdf'
5
+ config.mount_prefix = '/socialite'
6
+ end
@@ -0,0 +1,14 @@
1
+ # Be sure to restart your server when you modify this file.
2
+ #
3
+ # This file contains settings for ActionController::ParamsWrapper which
4
+ # is enabled by default.
5
+
6
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
+ ActiveSupport.on_load(:action_controller) do
8
+ wrap_parameters :format => [:json]
9
+ end
10
+
11
+ # Disable root element in JSON by default.
12
+ ActiveSupport.on_load(:active_record) do
13
+ self.include_root_in_json = false
14
+ end
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,11 @@
1
+ require 'socialite/engine'
2
+
3
+ Dummy::Application.routes.draw do
4
+ mount Socialite::Engine => '/socialite'
5
+ # resource :user, :module => 'socialite', :controller => 'user' do
6
+ # resources :identities, :only => [:destroy]
7
+ # end
8
+ # resource :home
9
+ match '/restricted' => 'home#show', :as => 'restricted'
10
+ root :to => 'home#index'
11
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,43 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended to check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(:version => 20110926005551) do
15
+
16
+ create_table "socialite_facebook_identities", :force => true do |t|
17
+ t.datetime "created_at"
18
+ t.datetime "updated_at"
19
+ end
20
+
21
+ create_table "socialite_identities", :force => true do |t|
22
+ t.integer "user_id"
23
+ t.integer "api_id"
24
+ t.string "api_type"
25
+ t.string "unique_id", :null => false
26
+ t.string "provider", :null => false
27
+ t.text "auth_hash"
28
+ t.datetime "created_at"
29
+ t.datetime "updated_at"
30
+ end
31
+
32
+ add_index "socialite_identities", ["api_id", "api_type"], :name => "index_socialite_identities_on_api_id_and_api_type"
33
+ add_index "socialite_identities", ["provider", "unique_id"], :name => "index_socialite_identities_on_provider_and_unique_id", :unique => true
34
+ add_index "socialite_identities", ["user_id", "provider"], :name => "index_socialite_identities_on_user_id_and_provider", :unique => true
35
+ add_index "socialite_identities", ["user_id"], :name => "index_socialite_identities_on_user_id"
36
+
37
+ create_table "socialite_users", :force => true do |t|
38
+ t.string "remember_token"
39
+ t.datetime "created_at"
40
+ t.datetime "updated_at"
41
+ end
42
+
43
+ end
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
24
+ </div>
25
+ </body>
26
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,5 @@
1
+ FactoryGirl.define do
2
+ factory :facebook_identity, :class => Socialite::FacebookIdentity do
3
+ # Attributes we may need should go here.
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ FactoryGirl.define do
2
+ factory :identity, :class => Socialite::Identity do
3
+ sequence(:unique_id, 1000) { |n| "abcdef#{n}" }
4
+ # association :user, :factory => :user, :method => :build
5
+ provider 'facebook'
6
+ auth_hash { x = { 'credentials' => {'token' => '123648493','secret' => '12477388272'} } }
7
+ association :api, :factory => :facebook_identity, :method => :build
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ FactoryGirl.define do
2
+ # factory :twitter_identity, :class => Socialite::TwitterIdentity do
3
+
4
+ # end
5
+ end
6
+
@@ -0,0 +1,16 @@
1
+ module Socialite
2
+ FactoryGirl.define do
3
+ factory :user, :class => Socialite::User do
4
+ # Something here
5
+ end
6
+
7
+ factory :linked_user, :parent => :user do
8
+ after_build do |user|
9
+ user.identities = [
10
+ FactoryGirl.build(:identity, :provider => 'facebook'),
11
+ FactoryGirl.build(:identity, :provider => 'twitter')
12
+ ]
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ module Socialite
4
+ describe FacebookIdentity do
5
+ subject { FactoryGirl.build(:facebook_identity) }
6
+ it_behaves_like 'facebook api'
7
+
8
+ describe '.api_connection' do
9
+ subject { Socialite::FacebookIdentity.api_connection }
10
+
11
+ it { should be_a(Koala::Facebook::API) }
12
+
13
+ it 'defaults to not using an access token' do
14
+ subject.access_token.should be_nil
15
+ end
16
+
17
+ context 'with specified access token' do
18
+ let!(:fake_token) { '1234567890' }
19
+ subject { Socialite::FacebookIdentity.api_connection(fake_token) }
20
+
21
+ it 'does not use an access_token unless specified' do
22
+ subject.should be_a(Koala::Facebook::API)
23
+ subject.access_token.should eql(fake_token)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ module Socialite
4
+ describe Identity do
5
+ let!(:identity) { FactoryGirl.create(:identity) }
6
+
7
+ it_behaves_like 'identity'
8
+ end
9
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ module Socialite
4
+ describe User do
5
+ let(:linked_user) { FactoryGirl.create(:linked_user) }
6
+
7
+ it { should have_many(:identities).dependent(:destroy) }
8
+ it { should have_one(:facebook_identity) }
9
+ it { should have_one(:twitter_identity) }
10
+
11
+ context 'with associated identities' do
12
+ subject { linked_user }
13
+
14
+ before do
15
+ subject.identities.count.should eql(2)
16
+ end
17
+
18
+ its('identities.count') { should eql(2) }
19
+
20
+ its(:facebook_identity) { should be_a(Socialite::Identity) }
21
+ its(:facebook) { should be_a(Socialite::FacebookIdentity) }
22
+
23
+ # its(:twitter_identity) { should be_a(Socialite::Identity) }
24
+ # its(:twitter) { should be_a(Socialite::TwitterIdentity) }
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,29 @@
1
+ # Configure Rails Envinronment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path('../dummy/config/environment.rb', __FILE__)
5
+ require 'rails/test_help'
6
+ require 'rspec/rails'
7
+
8
+ # Should matchers
9
+ require 'shoulda/matchers'
10
+
11
+ Rails.backtrace_cleaner.remove_silencers!
12
+
13
+ # Load support files
14
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
15
+
16
+ # Load factories
17
+ require 'factory_girl'
18
+ Dir["#{File.dirname(__FILE__)}/factories/**/*.rb"].each { |f| require f }
19
+
20
+ # Run any available migration
21
+ ActiveRecord::Migrator.migrate File.expand_path('../dummy/db/migrate/', __FILE__)
22
+
23
+ RSpec.configure do |config|
24
+ require 'rspec/expectations'
25
+ config.include RSpec::Matchers
26
+ # config.include Socialite::Identity
27
+
28
+ config.use_transactional_fixtures = true
29
+ end
File without changes
@@ -0,0 +1,13 @@
1
+ configs = YAML.load_file(File.join(File.dirname(__FILE__), 'databases.yml'))
2
+ ActiveRecord::Base.configurations = configs
3
+
4
+ db_name = ENV['DB'] || 'sqlite'
5
+ ActiveRecord::Base.establish_connection(db_name)
6
+ ActiveRecord::Base.default_timezone = :utc
7
+
8
+ load_schema = lambda {
9
+ # load File.join(File.dirname(__FILE__), "../dummy/db/schema.rb") # use db agnostic schema by default
10
+ ActiveRecord::Migrator.up(File.join(File.dirname(__FILE__), '../../db/migrate')) # use migrations
11
+ }
12
+ silence_stream(STDOUT, &load_schema)
13
+
@@ -0,0 +1,14 @@
1
+ # test/database.yml
2
+ sqlite:
3
+ adapter: sqlite3
4
+ database: ":memory:"
5
+ timeout: 500
6
+ mysql:
7
+ adapter: mysql2
8
+ database: socialite_test
9
+ username:
10
+ encoding: utf8
11
+ postgres:
12
+ adapter: postgresql
13
+ database: socialite_test
14
+ username: postgres
@@ -0,0 +1,67 @@
1
+ module Socialite
2
+ shared_examples 'identity' do
3
+ it { should belong_to(:user) }
4
+
5
+ it { should have_db_column(:unique_id) }
6
+ it { should have_db_column(:provider) }
7
+ it { should have_db_column(:auth_hash) }
8
+
9
+ it { should validate_presence_of(:unique_id) }
10
+ it { should validate_presence_of(:provider) }
11
+
12
+ it { should validate_uniqueness_of(:unique_id).scoped_to(:provider) }
13
+ it { should validate_uniqueness_of(:provider).scoped_to(:user_id).case_insensitive }
14
+
15
+ describe '.find_or_initialize_by_oauth' do
16
+ let(:auth_hash) do
17
+ {
18
+ 'provider' => 'facebook',
19
+ 'uid' => '555',
20
+ 'credentials' => {
21
+ 'token' => '123648493',
22
+ 'secret' => '12477388272'
23
+ }
24
+ }
25
+ end
26
+
27
+ describe 'facebook' do
28
+ # let(:fb_identity) { }
29
+ subject { Identity.find_or_initialize_by_oauth(auth_hash) }
30
+
31
+ it { should be_a(Identity) }
32
+ its(:persisted?) { should be_false }
33
+
34
+ context 'existing identity' do
35
+ let(:user) { FactoryGirl.create(:linked_user) }
36
+ let(:identity) { user.identities.first }
37
+ let(:auth_hash) { identity.auth_hash.merge('provider' => identity.provider, 'uid' => identity.unique_id) }
38
+ subject { Identity.find_or_initialize_by_oauth(auth_hash) }
39
+ before { user.identities.count.should > 0; identity.user.should be_present }
40
+
41
+ its(:persisted?) { should be_true }
42
+ its(:user) { should be_a(User) }
43
+ its(:user) { should eql(user) }
44
+ end
45
+ end
46
+
47
+ # describe 'twitter' do
48
+ # let(:twitter_identity) { subject.find_or_initialize_by_oauth(auth_hash.merge('provider' => 'twitter')) }
49
+ # subject { twitter_identity }
50
+
51
+ # it { should be_a(Identity) }
52
+ # its(:persisted?) { should be_true }
53
+ # its(:user) { should be_a(User) }
54
+ # end
55
+ end
56
+ end
57
+
58
+ shared_examples 'facebook api' do
59
+ it { should respond_to(:account_url) }
60
+ it { should respond_to(:api) }
61
+ it { should respond_to(:api_connection) }
62
+ it { should respond_to(:checkins) }
63
+ it { should respond_to(:friends) }
64
+ it { should respond_to(:picture) }
65
+ it { should respond_to(:info) }
66
+ end
67
+ end