billfold 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/.gitignore +1 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +3 -0
  4. data/README.md +39 -0
  5. data/Rakefile +26 -0
  6. data/VERSION +1 -0
  7. data/app/controllers/billfold/identities_controller.rb +53 -0
  8. data/app/views/billfold/identities/_list.html.erb +8 -0
  9. data/app/views/billfold/identities/index.html.erb +2 -0
  10. data/billfold.gemspec +24 -0
  11. data/config/locales/en.yml +6 -0
  12. data/config/routes.rb +11 -0
  13. data/lib/billfold.rb +56 -0
  14. data/lib/billfold/active_record_identity.rb +47 -0
  15. data/lib/billfold/active_record_user.rb +46 -0
  16. data/lib/billfold/controller_support.rb +51 -0
  17. data/lib/billfold/engine.rb +25 -0
  18. data/lib/billfold/identity.rb +99 -0
  19. data/lib/billfold/user.rb +25 -0
  20. data/lib/rails/generators/billfold/migration_generator.rb +27 -0
  21. data/lib/rails/generators/billfold/models_generator.rb +14 -0
  22. data/lib/rails/generators/billfold/templates/identity.rb +5 -0
  23. data/lib/rails/generators/billfold/templates/migration.rb +23 -0
  24. data/lib/rails/generators/billfold/templates/user.rb +5 -0
  25. data/spec/billfold_spec.rb +23 -0
  26. data/spec/controllers/identities_controller_spec.rb +31 -0
  27. data/spec/dummy/.gitignore +5 -0
  28. data/spec/dummy/README +261 -0
  29. data/spec/dummy/Rakefile +7 -0
  30. data/spec/dummy/app/assets/images/rails.png +0 -0
  31. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  32. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  33. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  34. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  35. data/spec/dummy/app/mailers/.gitkeep +0 -0
  36. data/spec/dummy/app/models/.gitkeep +0 -0
  37. data/spec/dummy/app/models/identity.rb +5 -0
  38. data/spec/dummy/app/models/user.rb +5 -0
  39. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  40. data/spec/dummy/config.ru +4 -0
  41. data/spec/dummy/config/application.rb +48 -0
  42. data/spec/dummy/config/boot.rb +6 -0
  43. data/spec/dummy/config/database.yml +25 -0
  44. data/spec/dummy/config/environment.rb +5 -0
  45. data/spec/dummy/config/environments/development.rb +30 -0
  46. data/spec/dummy/config/environments/production.rb +60 -0
  47. data/spec/dummy/config/environments/test.rb +42 -0
  48. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  49. data/spec/dummy/config/initializers/inflections.rb +10 -0
  50. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  51. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  52. data/spec/dummy/config/initializers/session_store.rb +8 -0
  53. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  54. data/spec/dummy/config/locales/en.yml +5 -0
  55. data/spec/dummy/config/routes.rb +58 -0
  56. data/spec/dummy/db/migrate/20110904204023_create_users_and_identities.rb +23 -0
  57. data/spec/dummy/db/schema.rb +31 -0
  58. data/spec/dummy/db/seeds.rb +7 -0
  59. data/spec/dummy/doc/README_FOR_APP +2 -0
  60. data/spec/dummy/lib/assets/.gitkeep +0 -0
  61. data/spec/dummy/lib/tasks/.gitkeep +0 -0
  62. data/spec/dummy/log/.gitkeep +0 -0
  63. data/spec/dummy/public/404.html +26 -0
  64. data/spec/dummy/public/422.html +26 -0
  65. data/spec/dummy/public/500.html +26 -0
  66. data/spec/dummy/public/favicon.ico +0 -0
  67. data/spec/dummy/public/index.html +241 -0
  68. data/spec/dummy/public/robots.txt +5 -0
  69. data/spec/dummy/script/rails +6 -0
  70. data/spec/dummy/test/fixtures/.gitkeep +0 -0
  71. data/spec/dummy/test/functional/.gitkeep +0 -0
  72. data/spec/dummy/test/integration/.gitkeep +0 -0
  73. data/spec/dummy/test/performance/browsing_test.rb +12 -0
  74. data/spec/dummy/test/test_helper.rb +13 -0
  75. data/spec/dummy/test/unit/.gitkeep +0 -0
  76. data/spec/dummy/vendor/assets/stylesheets/.gitkeep +0 -0
  77. data/spec/dummy/vendor/plugins/.gitkeep +0 -0
  78. data/spec/factories/identity_factories.rb +18 -0
  79. data/spec/factories/user_factories.rb +7 -0
  80. data/spec/models/identity_spec.rb +123 -0
  81. data/spec/spec_helper.rb +30 -0
  82. metadata +260 -0
@@ -0,0 +1,7 @@
1
+ Factory.sequence :user_name do |n|
2
+ "User #{n}"
3
+ end
4
+
5
+ Factory.define :user do |user|
6
+ user.name { Factory.next(:user_name) }
7
+ end
@@ -0,0 +1,123 @@
1
+ require 'spec_helper'
2
+
3
+ describe Identity do
4
+
5
+ subject { Identity }
6
+
7
+ describe '.update_or_create!' do
8
+
9
+ let(:user) { Factory(:user) }
10
+ let(:identity) { Factory(:twitter_identity) }
11
+ let(:uid) { Factory.next(:uid) }
12
+ let(:name) { 'Patricia Leone' }
13
+ let(:arguments) do
14
+ { :provider => 'twitter', :value => Factory.next(:twitter_handle) }
15
+ end
16
+
17
+ context 'with a nil provider' do
18
+ it 'raises an ArgumentError' do
19
+ lambda {
20
+ subject.update_or_create!(arguments.merge({ :provider => nil }))
21
+ }.should raise_error(ArgumentError)
22
+ end
23
+ end
24
+
25
+ context 'with a nil value' do
26
+ it 'raises an ArgumentError' do
27
+ lambda {
28
+ subject.update_or_create!(arguments.merge({ :value => nil }))
29
+ }.should raise_error(ArgumentError)
30
+ end
31
+ end
32
+
33
+ context 'with provider "twitter"' do
34
+ let(:arguments) {
35
+ {
36
+ :provider => 'twitter',
37
+ :value => uid,
38
+ :user => nil,
39
+ :data => { 'name' => name }
40
+ }
41
+ }
42
+
43
+ context 'and a nil user' do
44
+ it 'creates a user' do
45
+ expect { subject.update_or_create!(arguments) }.to change { User.count }.by(1)
46
+ end
47
+
48
+ it "uses the display name from the identity" do
49
+ id = subject.update_or_create!(arguments)
50
+ id.user.name.should == id.name_for_user
51
+ end
52
+ end
53
+
54
+ context 'and a previously-unused UID' do
55
+ before(:each) do
56
+ @result = subject.update_or_create!({
57
+ :provider => 'twitter',
58
+ :value => uid,
59
+ :user => user,
60
+ :data => { 'name' => name }
61
+ })
62
+ end
63
+
64
+ it 'returns a saved Identity' do
65
+ @result.should be_a(Identity)
66
+ @result.should_not be_new_record
67
+ end
68
+
69
+ it 'uses the correct provider' do
70
+ @result.provider.should == 'twitter'
71
+ end
72
+
73
+ it 'uses the correct value' do
74
+ @result.value.should == uid
75
+ end
76
+
77
+ it 'passes the "user_info" as data' do
78
+ @result.data['name'].should == name
79
+ end
80
+
81
+ it 'adds the identity to the user' do
82
+ @result.user.should == user
83
+ end
84
+ end
85
+
86
+ context 'and a UID previously used by the user' do
87
+ before(:each) do
88
+ @result = subject.update_or_create!({
89
+ :provider => 'twitter',
90
+ :value => identity.value,
91
+ :user => identity.user,
92
+ :data => { 'name' => 'new name' }
93
+ })
94
+ end
95
+
96
+ it 'updates the identity' do
97
+ identity.reload.data['name'].should == 'new name'
98
+ end
99
+ end
100
+
101
+ context 'and a UID previously used by another user' do
102
+ let(:other_user) { Factory(:user) }
103
+
104
+ before(:each) do
105
+ @original_user = identity.user
106
+ @original_user.should_not equal(other_user)
107
+ end
108
+
109
+ it 'merges the identity owner into the given user' do
110
+ Identity.expects(:with_provider_and_value).returns(identity)
111
+ @original_user.expects(:merge_into!).with(other_user)
112
+ subject.update_or_create!({
113
+ :provider => 'twitter',
114
+ :value => identity.value,
115
+ :user => other_user
116
+ })
117
+ end
118
+ end
119
+ end
120
+
121
+ end
122
+
123
+ end
@@ -0,0 +1,30 @@
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
+ require 'factory_girl'
8
+
9
+ ActionMailer::Base.delivery_method = :test
10
+ ActionMailer::Base.perform_deliveries = true
11
+ ActionMailer::Base.default_url_options[:host] = "test.com"
12
+
13
+ Rails.backtrace_cleaner.remove_silencers!
14
+
15
+ # Run any available migration
16
+ ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
17
+
18
+ # Load support files
19
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
20
+ Dir["#{File.dirname(__FILE__)}/factories/**/*.rb"].each { |f| require f }
21
+
22
+ RSpec.configure do |config|
23
+ # Remove this line if you don't want RSpec's should and should_not
24
+ # methods or matchers
25
+ require 'rspec/expectations'
26
+ config.include RSpec::Matchers
27
+
28
+ # == Mock Framework
29
+ config.mock_with :mocha
30
+ end
metadata ADDED
@@ -0,0 +1,260 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: billfold
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - James A. Rosen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-05 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &2164532580 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2164532580
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
27
+ requirement: &2164530980 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2164530980
36
+ - !ruby/object:Gem::Dependency
37
+ name: mocha
38
+ requirement: &2164529040 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2164529040
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: &2164527400 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2164527400
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec-rails
60
+ requirement: &2164522880 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2164522880
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: &2164486340 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *2164486340
80
+ - !ruby/object:Gem::Dependency
81
+ name: factory_girl
82
+ requirement: &2164480580 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *2164480580
91
+ description: Identity Management with OmniAuth
92
+ email:
93
+ - james.a.rosen@gmail.com
94
+ executables: []
95
+ extensions: []
96
+ extra_rdoc_files: []
97
+ files:
98
+ - .gitignore
99
+ - .rvmrc
100
+ - Gemfile
101
+ - README.md
102
+ - Rakefile
103
+ - VERSION
104
+ - app/controllers/billfold/identities_controller.rb
105
+ - app/views/billfold/identities/_list.html.erb
106
+ - app/views/billfold/identities/index.html.erb
107
+ - billfold.gemspec
108
+ - config/locales/en.yml
109
+ - config/routes.rb
110
+ - lib/billfold.rb
111
+ - lib/billfold/active_record_identity.rb
112
+ - lib/billfold/active_record_user.rb
113
+ - lib/billfold/controller_support.rb
114
+ - lib/billfold/engine.rb
115
+ - lib/billfold/identity.rb
116
+ - lib/billfold/user.rb
117
+ - lib/rails/generators/billfold/migration_generator.rb
118
+ - lib/rails/generators/billfold/models_generator.rb
119
+ - lib/rails/generators/billfold/templates/identity.rb
120
+ - lib/rails/generators/billfold/templates/migration.rb
121
+ - lib/rails/generators/billfold/templates/user.rb
122
+ - spec/billfold_spec.rb
123
+ - spec/controllers/identities_controller_spec.rb
124
+ - spec/dummy/.gitignore
125
+ - spec/dummy/README
126
+ - spec/dummy/Rakefile
127
+ - spec/dummy/app/assets/images/rails.png
128
+ - spec/dummy/app/assets/javascripts/application.js
129
+ - spec/dummy/app/assets/stylesheets/application.css
130
+ - spec/dummy/app/controllers/application_controller.rb
131
+ - spec/dummy/app/helpers/application_helper.rb
132
+ - spec/dummy/app/mailers/.gitkeep
133
+ - spec/dummy/app/models/.gitkeep
134
+ - spec/dummy/app/models/identity.rb
135
+ - spec/dummy/app/models/user.rb
136
+ - spec/dummy/app/views/layouts/application.html.erb
137
+ - spec/dummy/config.ru
138
+ - spec/dummy/config/application.rb
139
+ - spec/dummy/config/boot.rb
140
+ - spec/dummy/config/database.yml
141
+ - spec/dummy/config/environment.rb
142
+ - spec/dummy/config/environments/development.rb
143
+ - spec/dummy/config/environments/production.rb
144
+ - spec/dummy/config/environments/test.rb
145
+ - spec/dummy/config/initializers/backtrace_silencers.rb
146
+ - spec/dummy/config/initializers/inflections.rb
147
+ - spec/dummy/config/initializers/mime_types.rb
148
+ - spec/dummy/config/initializers/secret_token.rb
149
+ - spec/dummy/config/initializers/session_store.rb
150
+ - spec/dummy/config/initializers/wrap_parameters.rb
151
+ - spec/dummy/config/locales/en.yml
152
+ - spec/dummy/config/routes.rb
153
+ - spec/dummy/db/migrate/20110904204023_create_users_and_identities.rb
154
+ - spec/dummy/db/schema.rb
155
+ - spec/dummy/db/seeds.rb
156
+ - spec/dummy/doc/README_FOR_APP
157
+ - spec/dummy/lib/assets/.gitkeep
158
+ - spec/dummy/lib/tasks/.gitkeep
159
+ - spec/dummy/log/.gitkeep
160
+ - spec/dummy/public/404.html
161
+ - spec/dummy/public/422.html
162
+ - spec/dummy/public/500.html
163
+ - spec/dummy/public/favicon.ico
164
+ - spec/dummy/public/index.html
165
+ - spec/dummy/public/robots.txt
166
+ - spec/dummy/script/rails
167
+ - spec/dummy/test/fixtures/.gitkeep
168
+ - spec/dummy/test/functional/.gitkeep
169
+ - spec/dummy/test/integration/.gitkeep
170
+ - spec/dummy/test/performance/browsing_test.rb
171
+ - spec/dummy/test/test_helper.rb
172
+ - spec/dummy/test/unit/.gitkeep
173
+ - spec/dummy/vendor/assets/stylesheets/.gitkeep
174
+ - spec/dummy/vendor/plugins/.gitkeep
175
+ - spec/factories/identity_factories.rb
176
+ - spec/factories/user_factories.rb
177
+ - spec/models/identity_spec.rb
178
+ - spec/spec_helper.rb
179
+ homepage: http://github.com/jamesarosen/billfold
180
+ licenses: []
181
+ post_install_message:
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ none: false
187
+ requirements:
188
+ - - ! '>='
189
+ - !ruby/object:Gem::Version
190
+ version: '0'
191
+ required_rubygems_version: !ruby/object:Gem::Requirement
192
+ none: false
193
+ requirements:
194
+ - - ! '>='
195
+ - !ruby/object:Gem::Version
196
+ version: 1.3.6
197
+ requirements: []
198
+ rubyforge_project:
199
+ rubygems_version: 1.8.6
200
+ signing_key:
201
+ specification_version: 3
202
+ summary: Identity Management with OmniAuth
203
+ test_files:
204
+ - spec/billfold_spec.rb
205
+ - spec/controllers/identities_controller_spec.rb
206
+ - spec/dummy/.gitignore
207
+ - spec/dummy/README
208
+ - spec/dummy/Rakefile
209
+ - spec/dummy/app/assets/images/rails.png
210
+ - spec/dummy/app/assets/javascripts/application.js
211
+ - spec/dummy/app/assets/stylesheets/application.css
212
+ - spec/dummy/app/controllers/application_controller.rb
213
+ - spec/dummy/app/helpers/application_helper.rb
214
+ - spec/dummy/app/mailers/.gitkeep
215
+ - spec/dummy/app/models/.gitkeep
216
+ - spec/dummy/app/models/identity.rb
217
+ - spec/dummy/app/models/user.rb
218
+ - spec/dummy/app/views/layouts/application.html.erb
219
+ - spec/dummy/config.ru
220
+ - spec/dummy/config/application.rb
221
+ - spec/dummy/config/boot.rb
222
+ - spec/dummy/config/database.yml
223
+ - spec/dummy/config/environment.rb
224
+ - spec/dummy/config/environments/development.rb
225
+ - spec/dummy/config/environments/production.rb
226
+ - spec/dummy/config/environments/test.rb
227
+ - spec/dummy/config/initializers/backtrace_silencers.rb
228
+ - spec/dummy/config/initializers/inflections.rb
229
+ - spec/dummy/config/initializers/mime_types.rb
230
+ - spec/dummy/config/initializers/secret_token.rb
231
+ - spec/dummy/config/initializers/session_store.rb
232
+ - spec/dummy/config/initializers/wrap_parameters.rb
233
+ - spec/dummy/config/locales/en.yml
234
+ - spec/dummy/config/routes.rb
235
+ - spec/dummy/db/migrate/20110904204023_create_users_and_identities.rb
236
+ - spec/dummy/db/schema.rb
237
+ - spec/dummy/db/seeds.rb
238
+ - spec/dummy/doc/README_FOR_APP
239
+ - spec/dummy/lib/assets/.gitkeep
240
+ - spec/dummy/lib/tasks/.gitkeep
241
+ - spec/dummy/log/.gitkeep
242
+ - spec/dummy/public/404.html
243
+ - spec/dummy/public/422.html
244
+ - spec/dummy/public/500.html
245
+ - spec/dummy/public/favicon.ico
246
+ - spec/dummy/public/index.html
247
+ - spec/dummy/public/robots.txt
248
+ - spec/dummy/script/rails
249
+ - spec/dummy/test/fixtures/.gitkeep
250
+ - spec/dummy/test/functional/.gitkeep
251
+ - spec/dummy/test/integration/.gitkeep
252
+ - spec/dummy/test/performance/browsing_test.rb
253
+ - spec/dummy/test/test_helper.rb
254
+ - spec/dummy/test/unit/.gitkeep
255
+ - spec/dummy/vendor/assets/stylesheets/.gitkeep
256
+ - spec/dummy/vendor/plugins/.gitkeep
257
+ - spec/factories/identity_factories.rb
258
+ - spec/factories/user_factories.rb
259
+ - spec/models/identity_spec.rb
260
+ - spec/spec_helper.rb