socialite 0.0.1.beta4 → 0.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. data/README.md +33 -34
  2. data/Rakefile +8 -21
  3. data/app/controllers/socialite/application_controller.rb +4 -0
  4. data/app/controllers/socialite/identities_controller.rb +2 -14
  5. data/app/controllers/socialite/session_controller.rb +20 -0
  6. data/app/controllers/socialite/users_controller.rb +0 -1
  7. data/app/views/layouts/socialite/application.html.haml +11 -0
  8. data/app/views/socialite/identities/new.html.haml +27 -0
  9. data/app/views/socialite/session/new.html.haml +31 -14
  10. data/app/views/socialite/user/edit.html.haml +1 -1
  11. data/config/routes.rb +7 -7
  12. data/lib/generators/socialite/install_generator.rb +7 -9
  13. data/lib/generators/socialite/migrations_generator.rb +34 -0
  14. data/lib/generators/socialite/templates/identity.rb.erb +25 -0
  15. data/lib/generators/socialite/templates/socialite.rb +20 -7
  16. data/lib/generators/socialite/templates/users.rb.erb +12 -0
  17. data/lib/socialite.rb +25 -27
  18. data/lib/socialite/controllers/helpers.rb +107 -111
  19. data/lib/socialite/engine.rb +19 -32
  20. data/lib/socialite/helpers/authentication.rb +1 -1
  21. data/lib/socialite/models/identity_concern.rb +91 -0
  22. data/lib/socialite/models/user_concern.rb +54 -0
  23. data/lib/socialite/version.rb +1 -1
  24. data/spec/dummy/README.rdoc +261 -0
  25. data/spec/dummy/app/assets/javascripts/application.js +9 -3
  26. data/spec/dummy/app/assets/stylesheets/application.css +11 -5
  27. data/{app/assets/images/socialite → spec/dummy/app/mailers}/.gitkeep +0 -0
  28. data/{app/assets/javascripts/socialite → spec/dummy/app/models}/.gitkeep +0 -0
  29. data/spec/dummy/app/models/identity.rb +4 -0
  30. data/spec/dummy/app/models/user.rb +4 -0
  31. data/spec/dummy/app/views/layouts/application.html.erb +1 -5
  32. data/spec/dummy/config/application.rb +19 -2
  33. data/spec/dummy/config/boot.rb +1 -11
  34. data/spec/dummy/config/database.yml +18 -2
  35. data/spec/dummy/config/environments/development.rb +8 -1
  36. data/spec/dummy/config/environments/production.rb +9 -2
  37. data/spec/dummy/config/environments/test.rb +4 -9
  38. data/spec/dummy/config/initializers/inflections.rb +5 -0
  39. data/spec/dummy/config/initializers/secret_token.rb +1 -1
  40. data/spec/dummy/config/initializers/session_store.rb +1 -1
  41. data/spec/dummy/config/initializers/socialite.rb +26 -4
  42. data/spec/dummy/config/initializers/wrap_parameters.rb +1 -1
  43. data/spec/dummy/config/routes.rb +2 -10
  44. data/{db/migrate/20110914215410_create_users.rb → spec/dummy/db/migrate/20130206224516_create_socialite_users.rb} +2 -4
  45. data/spec/dummy/db/migrate/20130206224517_create_socialite_identities.rb +25 -0
  46. data/spec/dummy/db/schema.rb +12 -20
  47. data/{lib/tasks → spec/dummy/lib/assets}/.gitkeep +0 -0
  48. data/spec/dummy/log/.gitkeep +0 -0
  49. data/spec/dummy/public/500.html +0 -1
  50. data/spec/factories/facebook.rb +5 -5
  51. data/spec/factories/identity.rb +3 -3
  52. data/spec/factories/user.rb +10 -12
  53. data/spec/generators/socialite/install_generator_spec.rb +43 -0
  54. data/spec/generators/socialite/migrations_generator_spec.rb +27 -0
  55. data/spec/models/facebook_spec.rb +24 -21
  56. data/spec/models/identity_spec.rb +2 -2
  57. data/spec/models/user_spec.rb +7 -7
  58. data/spec/socialite_spec.rb +53 -0
  59. data/spec/spec_helper.rb +23 -10
  60. data/spec/support/identity_shared_example.rb +24 -20
  61. metadata +202 -144
  62. data/.autotest +0 -7
  63. data/.gitignore +0 -9
  64. data/.rspec +0 -2
  65. data/.travis.yml +0 -10
  66. data/.yardopts +0 -8
  67. data/Gemfile +0 -8
  68. data/Gemfile.lock +0 -208
  69. data/app/models/socialite/facebook_identity.rb +0 -5
  70. data/app/models/socialite/identity.rb +0 -5
  71. data/app/models/socialite/user.rb +0 -10
  72. data/config/initializers/simple_form.rb +0 -90
  73. data/config/locales/simple_form.en.yml +0 -23
  74. data/db/migrate/20110925224222_create_identities.rb +0 -26
  75. data/db/migrate/20110926005551_create_facebook_identities.rb +0 -12
  76. data/lib/socialite/api_wrappers/facebook.rb +0 -67
  77. data/lib/socialite/api_wrappers/twitter.rb +0 -19
  78. data/lib/socialite/models/identity.rb +0 -99
  79. data/lib/socialite/models/user.rb +0 -50
  80. data/lib/socialite/service_config.rb +0 -14
  81. data/lib/tasks/cucumber.rake +0 -65
  82. data/script/cucumber +0 -10
  83. data/script/rails +0 -6
  84. data/socialite.gemspec +0 -39
  85. data/spec/dummy/app/controllers/home_controller.rb +0 -11
  86. data/spec/dummy/app/views/home/index.html.haml +0 -12
  87. data/spec/dummy/app/views/home/show.html.haml +0 -6
@@ -20,7 +20,7 @@ Dummy::Application.configure do
20
20
  # Generate digests for assets URLs
21
21
  config.assets.digest = true
22
22
 
23
- # Defaults to Rails.root.join("public/assets")
23
+ # Defaults to nil and saved in location specified by config.assets.prefix
24
24
  # config.assets.manifest = YOUR_PATH
25
25
 
26
26
  # Specifies the header that your server uses for sending files
@@ -33,8 +33,11 @@ Dummy::Application.configure do
33
33
  # See everything in the log (default is :info)
34
34
  # config.log_level = :debug
35
35
 
36
+ # Prepend all log lines with the following tags
37
+ # config.log_tags = [ :subdomain, :uuid ]
38
+
36
39
  # Use a different logger for distributed setups
37
- # config.logger = SyslogLogger.new
40
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
38
41
 
39
42
  # Use a different cache store in production
40
43
  # config.cache_store = :mem_cache_store
@@ -57,4 +60,8 @@ Dummy::Application.configure do
57
60
 
58
61
  # Send deprecation notices to registered listeners
59
62
  config.active_support.deprecation = :notify
63
+
64
+ # Log the query plan for queries taking more than this (works
65
+ # with SQLite, MySQL, and PostgreSQL)
66
+ # config.active_record.auto_explain_threshold_in_seconds = 0.5
60
67
  end
@@ -2,9 +2,9 @@ Dummy::Application.configure do
2
2
  # Settings specified here will take precedence over those in config/application.rb
3
3
 
4
4
  # The test environment is used exclusively to run your application's
5
- # test suite. You never need to work with it otherwise. Remember that
5
+ # test suite. You never need to work with it otherwise. Remember that
6
6
  # your test database is "scratch space" for the test suite and is wiped
7
- # and recreated between test runs. Don't rely on the data there!
7
+ # and recreated between test runs. Don't rely on the data there!
8
8
  config.cache_classes = true
9
9
 
10
10
  # Configure static asset server for tests with Cache-Control for performance
@@ -29,14 +29,9 @@ Dummy::Application.configure do
29
29
  # ActionMailer::Base.deliveries array.
30
30
  config.action_mailer.delivery_method = :test
31
31
 
32
- # Use SQL instead of Active Record's schema dumper when creating the test database.
33
- # This is necessary if your schema can't be completely dumped by the schema dumper,
34
- # like if you have constraints or database-specific column types
35
- # config.active_record.schema_format = :sql
32
+ # Raise exception on mass assignment protection for Active Record models
33
+ config.active_record.mass_assignment_sanitizer = :strict
36
34
 
37
35
  # Print deprecation notices to the stderr
38
36
  config.active_support.deprecation = :stderr
39
-
40
- # Allow pass debug_assets=true as a query parameter to load pages with unpackaged assets
41
- config.assets.allow_debugging = true
42
37
  end
@@ -8,3 +8,8 @@
8
8
  # inflect.irregular 'person', 'people'
9
9
  # inflect.uncountable %w( fish sheep )
10
10
  # end
11
+ #
12
+ # These inflection rules are supported but not enabled by default:
13
+ # ActiveSupport::Inflector.inflections do |inflect|
14
+ # inflect.acronym 'RESTful'
15
+ # end
@@ -4,4 +4,4 @@
4
4
  # If you change this key, all old signed cookies will become invalid!
5
5
  # Make sure the secret is at least 30 characters and all random,
6
6
  # no regular words or you'll be exposed to dictionary attacks.
7
- Dummy::Application.config.secret_token = '4b232d389ba2c60db3997624e83822d79577a385e82149d0a277baa7e0e8a9898fdb21b3264f9be0bd0154e7e792e4cdf52a7c0f36e93042cb247ae72b0c61e6'
7
+ Dummy::Application.config.secret_token = 'dd75c273d85209af29b6c0cc7ddb7ef057221d5643dd1d67636895a9fb94c5191e6c79382b6afa34b0336feaf7e30d7598551fae7349d80c6c5279b5910b8f5d'
@@ -1,6 +1,6 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
3
+ Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
4
4
 
5
5
  # Use the database for sessions instead of the cookie-based default,
6
6
  # which shouldn't be used to store highly confidential information
@@ -1,6 +1,28 @@
1
- require 'socialite'
2
-
3
1
  Socialite.setup do |config|
4
- config.facebook '281326728563029', '48f0828a7e5530c8ae0e2c32dd6c6cdf'
5
- config.mount_prefix = '/socialite'
2
+ ## Configure Classes
3
+ # If you are not using the default names set below. Please change them to
4
+ # reflect the correct classes.
5
+ #
6
+ # **NOTE** These _should_ be set to string values to prevent any possible
7
+ # errors caused by load order.
8
+ config.user_class = 'User'
9
+ config.identity_class = 'Identity'
10
+
11
+ ## Add any supported OmniAuth providers
12
+ # You can pass any providers that are supported by OmniAuth simply by
13
+ # including it in your Gemfile.
14
+ #
15
+ # Examples:
16
+ # config.provider :facebook, ENV['FACEBOOK_APP_KEY'], ENV['FACEBOOK_SECRET'],
17
+ # :scope => 'email,friends'
18
+ # config.provider :identity, :on_failed_registration => lambda { |env|
19
+ # UsersController.action(:new).call(env)
20
+ # }
21
+ # config.provider :twitter, ENV['TWITTER_APP_KEY'], ENV['TWITTER_SECRET']
22
+
23
+ if Rails.env.production?
24
+ # Any production specific information
25
+ elsif Rails.env.development?
26
+ # Configs for development mode go here
27
+ end
6
28
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
7
  ActiveSupport.on_load(:action_controller) do
8
- wrap_parameters :format => [:json]
8
+ wrap_parameters format: [:json]
9
9
  end
10
10
 
11
11
  # Disable root element in JSON by default.
@@ -1,11 +1,3 @@
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'
1
+ Rails.application.routes.draw do
2
+ mount Socialite::Engine => "/socialite"
11
3
  end
@@ -1,9 +1,7 @@
1
- class CreateUsers < ActiveRecord::Migration
1
+ class CreateSocialiteUsers < ActiveRecord::Migration
2
2
  def up
3
3
  create_table :socialite_users do |t|
4
- t.string :remember_token
5
- # Any additional fields here
6
-
4
+ t.string :name
7
5
  t.timestamps
8
6
  end
9
7
  end
@@ -0,0 +1,25 @@
1
+ class CreateSocialiteIdentities < ActiveRecord::Migration
2
+ def up
3
+ create_table :socialite_identities do |t|
4
+ t.string :uid, :provider
5
+ t.text :auth_hash
6
+ t.integer :socialite_user_id
7
+ t.timestamps
8
+ end
9
+
10
+ add_index :socialite_identities,
11
+ :socialite_user_id
12
+
13
+ # Restrict each user to one identity per provider, to disable comment out.
14
+ add_index :socialite_identities,
15
+ [:socialite_user_id, :provider], :unique => true
16
+
17
+ # Database constraint to ensure uniqueness of UIDs (scoped to provider)
18
+ add_index :socialite_identities,
19
+ [:provider, :uid], :unique => true
20
+ end
21
+
22
+ def down
23
+ drop_table :socialite_identities
24
+ end
25
+ end
@@ -11,33 +11,25 @@
11
11
  #
12
12
  # It's strongly recommended to check this file into your version control system.
13
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
14
+ ActiveRecord::Schema.define(:version => 20130206224517) do
20
15
 
21
16
  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
17
+ t.string "uid"
18
+ t.string "provider"
27
19
  t.text "auth_hash"
28
- t.datetime "created_at"
29
- t.datetime "updated_at"
20
+ t.integer "socialite_user_id"
21
+ t.datetime "created_at", :null => false
22
+ t.datetime "updated_at", :null => false
30
23
  end
31
24
 
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"
25
+ add_index "socialite_identities", ["provider", "uid"], :name => "index_socialite_identities_on_provider_and_uid", :unique => true
26
+ add_index "socialite_identities", ["socialite_user_id", "provider"], :name => "index_socialite_identities_on_socialite_user_id_and_provider", :unique => true
27
+ add_index "socialite_identities", ["socialite_user_id"], :name => "index_socialite_identities_on_socialite_user_id"
36
28
 
37
29
  create_table "socialite_users", :force => true do |t|
38
- t.string "remember_token"
39
- t.datetime "created_at"
40
- t.datetime "updated_at"
30
+ t.string "name"
31
+ t.datetime "created_at", :null => false
32
+ t.datetime "updated_at", :null => false
41
33
  end
42
34
 
43
35
  end
File without changes
@@ -20,7 +20,6 @@
20
20
  <!-- This file lives in public/500.html -->
21
21
  <div class="dialog">
22
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
23
  </div>
25
24
  </body>
26
25
  </html>
@@ -1,5 +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
1
+ # FactoryGirl.define do
2
+ # factory :facebook_identity, :class => MyFacebookIdentity do
3
+ # # Attributes we may need should go here.
4
+ # end
5
+ # end
@@ -1,9 +1,9 @@
1
1
  FactoryGirl.define do
2
- factory :identity, :class => Socialite::Identity do
3
- sequence(:unique_id, 1000) { |n| "abcdef#{n}" }
2
+ factory :identity do
3
+ sequence(:uid, 1000) { |n| "abcdef#{n}" }
4
4
  # association :user, :factory => :user, :method => :build
5
5
  provider 'facebook'
6
6
  auth_hash { x = { 'credentials' => {'token' => '123648493','secret' => '12477388272'} } }
7
- association :api, :factory => :facebook_identity, :method => :build
7
+ # association :api, :factory => :facebook_identity, :method => :build
8
8
  end
9
9
  end
@@ -1,16 +1,14 @@
1
- module Socialite
2
- FactoryGirl.define do
3
- factory :user, :class => Socialite::User do
4
- # Something here
5
- end
1
+ FactoryGirl.define do
2
+ factory :user do
3
+ # Something here
4
+ end
6
5
 
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
6
+ factory :linked_user, :parent => :user do
7
+ after(:build) do |user|
8
+ user.identities = [
9
+ FactoryGirl.build(:identity, :provider => 'facebook'),
10
+ FactoryGirl.build(:identity, :provider => 'twitter')
11
+ ]
14
12
  end
15
13
  end
16
14
  end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+ require "generators/socialite/install_generator"
3
+
4
+ describe Socialite::Generators::InstallGenerator do
5
+ destination File.expand_path("../../../../tmp", __FILE__)
6
+
7
+ before(:each) do
8
+ prepare_destination
9
+ %w(config script).each do |dir|
10
+ `ln -s #{Rails.root + dir} #{destination_root}`
11
+ end
12
+ end
13
+
14
+ after(:each) do
15
+ unless example.exception
16
+ prepare_destination
17
+ end
18
+ end
19
+
20
+ # using mocks to ensure proper methods are called
21
+ # invoke_all - will call all the tasks in the generator
22
+ it 'should run all tasks in the generator' do
23
+ gen = generator %w(install)
24
+ gen.should_receive :copy_initializer
25
+ capture(:stdout) { gen.invoke_all }
26
+ end
27
+
28
+ # custom matchers make it easy to verify what the generator creates
29
+ describe 'the generated files' do
30
+ before do
31
+ run_generator %w(install)
32
+ end
33
+ describe 'the spec' do
34
+ # file - gives you the absolute path where the generator will create the file
35
+ subject { file('config/initializers/socialite.rb') }
36
+ # should exist - verifies the file exists
37
+ it { should exist }
38
+
39
+ # should contain - verifies the file's contents
40
+ it { should contain(/Socialite.setup do \|config\|/) }
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ require "generators/socialite/migrations_generator"
3
+
4
+ describe Socialite::Generators::MigrationsGenerator do
5
+ destination File.expand_path("../../../../tmp", __FILE__)
6
+
7
+ before(:each) do
8
+ prepare_destination
9
+ %w(config script).each do |dir|
10
+ `ln -s #{Rails.root + dir} #{destination_root}`
11
+ end
12
+ end
13
+
14
+ after(:each) do
15
+ unless example.exception
16
+ prepare_destination
17
+ end
18
+ end
19
+
20
+ # using mocks to ensure proper methods are called
21
+ # invoke_all - will call all the tasks in the generator
22
+ it 'should run all tasks in the generator' do
23
+ gen = generator %w(migrations)
24
+ gen.should_receive :copy_migrations
25
+ capture(:stdout) { gen.invoke_all }
26
+ end
27
+ end
@@ -1,28 +1,31 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Socialite
4
- describe FacebookIdentity do
5
- subject { FactoryGirl.build(:facebook_identity) }
6
- it_behaves_like 'facebook api'
3
+ # module Socialite
4
+ # describe FacebookIdentity do
5
+ # # subject { MyFacebookIdentity.new }
6
+ # before { pending }
7
7
 
8
- describe '.api_connection' do
9
- subject { Socialite::FacebookIdentity.api_connection }
8
+ # subject { FactoryGirl.build(:facebook_identity) }
9
+ # it_behaves_like 'facebook api'
10
10
 
11
- it { should be_a(Koala::Facebook::API) }
11
+ # describe '.api_connection' do
12
+ # subject { Socialite::FacebookIdentity.api_connection }
12
13
 
13
- it 'defaults to not using an access token' do
14
- subject.access_token.should be_nil
15
- end
14
+ # it { should be_a(Koala::Facebook::API) }
16
15
 
17
- context 'with specified access token' do
18
- let!(:fake_token) { '1234567890' }
19
- subject { Socialite::FacebookIdentity.api_connection(fake_token) }
16
+ # it 'defaults to not using an access token' do
17
+ # subject.access_token.should be_nil
18
+ # end
20
19
 
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
20
+ # context 'with specified access token' do
21
+ # let!(:fake_token) { '1234567890' }
22
+ # subject { Socialite::FacebookIdentity.api_connection(fake_token) }
23
+
24
+ # it 'does not use an access_token unless specified' do
25
+ # subject.should be_a(Koala::Facebook::API)
26
+ # subject.access_token.should eql(fake_token)
27
+ # end
28
+ # end
29
+ # end
30
+ # end
31
+ # end
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Socialite
3
+ # module Socialite
4
4
  describe Identity do
5
5
  let!(:identity) { FactoryGirl.create(:identity) }
6
6
 
7
7
  it_behaves_like 'identity'
8
8
  end
9
- end
9
+ # end
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Socialite
3
+ # module Socialite
4
4
  describe User do
5
5
  let(:linked_user) { FactoryGirl.create(:linked_user) }
6
6
 
7
7
  it { should have_many(:identities).dependent(:destroy) }
8
- it { should have_one(:facebook_identity) }
9
- it { should have_one(:twitter_identity) }
8
+ # it { should have_one(:facebook_identity) }
9
+ # it { should have_one(:twitter_identity) }
10
10
 
11
11
  context 'with associated identities' do
12
12
  subject { linked_user }
@@ -17,11 +17,11 @@ module Socialite
17
17
 
18
18
  its('identities.count') { should eql(2) }
19
19
 
20
- its(:facebook_identity) { should be_a(Socialite::Identity) }
21
- its(:facebook) { should be_a(Socialite::FacebookIdentity) }
20
+ its(:facebook_identity) { should be_a(identity_class) }
21
+ # its(:facebook) { should be_a(Socialite::FacebookIdentity) }
22
22
 
23
- # its(:twitter_identity) { should be_a(Socialite::Identity) }
23
+ its(:twitter_identity) { should be_a(identity_class) }
24
24
  # its(:twitter) { should be_a(Socialite::TwitterIdentity) }
25
25
  end
26
26
  end
27
- end
27
+ # end