stormpath-rails 0.4.3 → 0.4.4
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.
- data/.gitignore +1 -1
- data/README.md +25 -11
- data/lib/generators/stormpath/rails/install/install_generator.rb +3 -13
- data/lib/generators/stormpath/rails/migration/migration_generator.rb +17 -0
- data/lib/generators/stormpath/rails/templates/stormpath.yml +11 -0
- data/lib/generators/stormpath/rails/templates/update_account_model.rb +10 -0
- data/lib/stormpath/rails/account.rb +1 -1
- data/lib/stormpath/rails/client.rb +4 -4
- data/lib/stormpath/rails/version.rb +1 -1
- data/spec/generators/install_generator_spec.rb +17 -0
- data/spec/generators/migration_generator_spec.rb +19 -0
- data/stormpath-rails.gemspec +1 -0
- metadata +25 -4
- data/spec/generators/stormpath/rails/install/install_generator_spec.rb +0 -9
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,30 +1,44 @@
|
|
1
|
-
# Stormpath::Rails
|
2
|
-
|
3
1
|
[](http://travis-ci.org/stormpath/stormpath-rails)
|
2
|
+
[](https://codeclimate.com/github/stormpath/stormpath-rails)
|
3
|
+
|
4
|
+
# Ruby on Rails support for Stormpath
|
4
5
|
|
5
|
-
|
6
|
+
## Gem Setup
|
6
7
|
|
7
|
-
|
8
|
+
Reference gem from Gemfile.
|
8
9
|
|
10
|
+
```ruby
|
9
11
|
add gem 'stormpath-rails' to Gemfile
|
12
|
+
```
|
13
|
+
|
14
|
+
Generate configuration file, then create directory per environment at stormpath and update stormpath.yml with corresponding directory hrefs.
|
15
|
+
|
16
|
+
```sh
|
17
|
+
rails g stormpath:rails:install
|
18
|
+
```
|
10
19
|
|
11
|
-
run rails g stormpath:rails:install
|
12
20
|
|
13
|
-
|
21
|
+
Generate and run migration, if you're on ActiveRecord. Skip this step for Mongoid.
|
14
22
|
|
15
|
-
|
23
|
+
```sh
|
24
|
+
rails g stormpath:rails:migration user
|
25
|
+
rake db:migrate
|
26
|
+
```
|
27
|
+
|
28
|
+
Update your model file.
|
16
29
|
|
17
30
|
```ruby
|
18
31
|
class User < ActiveRecord:Base
|
19
|
-
|
32
|
+
include Stormpath::Rails::Account
|
20
33
|
end
|
21
34
|
```
|
22
35
|
|
23
|
-
add stormpath_url column to store stormpath UID.
|
24
|
-
|
25
36
|
## TODO
|
26
37
|
|
27
|
-
|
38
|
+
+ Automatic directory layout (test, development, production) creation
|
39
|
+
+ Preventive validation to not send invalid data to stormpath.
|
40
|
+
+ Preventive validation to not send invalid data to stormpath.
|
41
|
+
+ Solve n+1 request problem when requesting account collection.
|
28
42
|
|
29
43
|
## Contributing
|
30
44
|
|
@@ -2,20 +2,10 @@ module Stormpath
|
|
2
2
|
module Rails
|
3
3
|
module Generators
|
4
4
|
class InstallGenerator < ::Rails::Generators::Base
|
5
|
-
|
6
|
-
create_file "config/stormpath.yml", "common:
|
7
|
-
href: <%= ENV['STORMPATH_URL'] %>
|
8
|
-
application: https://api.stormpath.com/v1/applications/<application id>
|
9
|
-
|
10
|
-
development:
|
11
|
-
root: https://api.stormpath.com/v1/directories/<root directory id>
|
5
|
+
source_root File.expand_path('../../templates', __FILE__)
|
12
6
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
production:
|
17
|
-
root: https://api.stormpath.com/v1/directories/<root directory id>
|
18
|
-
"
|
7
|
+
def create_initializer_file
|
8
|
+
template "stormpath.yml", "config/stormpath.yml"
|
19
9
|
end
|
20
10
|
end
|
21
11
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "active_support/core_ext/string/inflections"
|
2
|
+
|
3
|
+
module Stormpath
|
4
|
+
module Rails
|
5
|
+
module Generators
|
6
|
+
class MigrationGenerator < ::Rails::Generators::Base
|
7
|
+
argument :model_name, type: :string, default: "user", banner: "Account model name"
|
8
|
+
source_root File.expand_path('../../templates', __FILE__)
|
9
|
+
|
10
|
+
def create_migration_file
|
11
|
+
template "update_account_model.rb",
|
12
|
+
"db/migrate/#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_add_stormpath_url_to_#{model_name.pluralize}.rb"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
common:
|
2
|
+
stormpath_url: <%%= ENV['STORMPATH_URL'] %>
|
3
|
+
|
4
|
+
development:
|
5
|
+
root: https://api.stormpath.com/v1/directories/<root directory id>
|
6
|
+
|
7
|
+
test:
|
8
|
+
root: https://api.stormpath.com/v1/directories/<root directory id>
|
9
|
+
|
10
|
+
production:
|
11
|
+
root: https://api.stormpath.com/v1/directories/<root directory id>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class AddStormpathUrlTo<%= model_name.pluralize.camelize %> < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
add_column :<%= model_name.pluralize %>, :stormpath_url, :string
|
4
|
+
add_index :<%= model_name.pluralize %>, :stormpath_url
|
5
|
+
end
|
6
|
+
|
7
|
+
def down
|
8
|
+
remove_column :<%= model_name.pluralize %>, :stormpath_url
|
9
|
+
end
|
10
|
+
end
|
@@ -15,8 +15,8 @@ module Stormpath
|
|
15
15
|
self.partial_updates = false if self.respond_to?(:partial_updates)
|
16
16
|
|
17
17
|
#Mongoid specific declaration
|
18
|
-
#TODO index?
|
19
18
|
field(:stormpath_url, type: String) if self.respond_to?(:field)
|
19
|
+
index({ stormpath_url: 1 }, { unique: true }) if self.respond_to?(:index)
|
20
20
|
|
21
21
|
attr_accessor *STORMPATH_FIELDS
|
22
22
|
attr_accessible *STORMPATH_FIELDS
|
@@ -11,18 +11,18 @@ module Stormpath
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.authenticate_account(login, password)
|
14
|
-
application = self.ds.get_resource Config[:
|
14
|
+
application = self.ds.get_resource Config[:stormpath_url], ::Application
|
15
15
|
auth_result = application.authenticate_account ::UsernamePasswordRequest.new(login, password)
|
16
16
|
auth_result.get_account
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.send_password_reset_email(login_or_email)
|
20
|
-
application = self.ds.get_resource Config[:
|
20
|
+
application = self.ds.get_resource Config[:stormpath_url], ::Application
|
21
21
|
application.send_password_reset_email login_or_email
|
22
22
|
end
|
23
23
|
|
24
24
|
def self.verify_password_reset_token(token)
|
25
|
-
application = self.ds.get_resource Config[:
|
25
|
+
application = self.ds.get_resource Config[:stormpath_url], ::Application
|
26
26
|
application.verify_password_reset_token token
|
27
27
|
end
|
28
28
|
|
@@ -63,7 +63,7 @@ module Stormpath
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def self.client
|
66
|
-
self.connection ||= ::ClientApplicationBuilder.new.set_application_href(Config[:href]).build
|
66
|
+
self.connection ||= ::ClientApplicationBuilder.new.set_application_href(Config[:stormpath_url] || Config[:href]).build
|
67
67
|
self.connection.client
|
68
68
|
end
|
69
69
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "active_support/core_ext/class/attribute_accessors"
|
2
|
+
require "generator_spec/test_case"
|
3
|
+
require "generators/stormpath/rails/install/install_generator"
|
4
|
+
|
5
|
+
describe Stormpath::Rails::Generators::InstallGenerator do
|
6
|
+
include GeneratorSpec::TestCase
|
7
|
+
destination File.expand_path("../tmp", __FILE__)
|
8
|
+
|
9
|
+
before(:all) do
|
10
|
+
prepare_destination
|
11
|
+
run_generator
|
12
|
+
end
|
13
|
+
|
14
|
+
it "creates configuration file" do
|
15
|
+
assert_file "config/stormpath.yml", "common:\n stormpath_url: <%= ENV['STORMPATH_URL'] %>\n\ndevelopment:\n root: https://api.stormpath.com/v1/directories/<root directory id>\n\ntest:\n root: https://api.stormpath.com/v1/directories/<root directory id>\n\nproduction:\n root: https://api.stormpath.com/v1/directories/<root directory id>\n"
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "active_support/core_ext/class/attribute_accessors"
|
2
|
+
require "generator_spec/test_case"
|
3
|
+
require "generators/stormpath/rails/migration/migration_generator"
|
4
|
+
|
5
|
+
describe Stormpath::Rails::Generators::MigrationGenerator do
|
6
|
+
include GeneratorSpec::TestCase
|
7
|
+
destination File.expand_path("../tmp", __FILE__)
|
8
|
+
arguments %w(person)
|
9
|
+
|
10
|
+
before(:all) do
|
11
|
+
Time.stub_chain(:now, :utc, :strftime).and_return("0")
|
12
|
+
prepare_destination
|
13
|
+
run_generator
|
14
|
+
end
|
15
|
+
|
16
|
+
it "creates configuration file" do
|
17
|
+
assert_file "db/migrate/0_add_stormpath_url_to_people.rb", "class AddStormpathUrlToPeople < ActiveRecord::Migration\n def up\n add_column :people, :stormpath_url, :string\n add_index :people, :stormpath_url\n end\n\n def down\n remove_column :people, :stormpath_url\n end\nend"
|
18
|
+
end
|
19
|
+
end
|
data/stormpath-rails.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |gem|
|
|
20
20
|
|
21
21
|
gem.add_development_dependency('rake', '~> 10.0.2')
|
22
22
|
gem.add_development_dependency('rspec', '~> 2.12.0')
|
23
|
+
gem.add_development_dependency('generator_spec')
|
23
24
|
gem.add_development_dependency('activerecord')
|
24
25
|
gem.add_development_dependency('sqlite3')
|
25
26
|
gem.add_development_dependency('mongoid')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stormpath-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -75,6 +75,22 @@ dependencies:
|
|
75
75
|
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: 2.12.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: generator_spec
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
78
94
|
- !ruby/object:Gem::Dependency
|
79
95
|
name: activerecord
|
80
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -187,13 +203,17 @@ files:
|
|
187
203
|
- README.md
|
188
204
|
- Rakefile
|
189
205
|
- lib/generators/stormpath/rails/install/install_generator.rb
|
206
|
+
- lib/generators/stormpath/rails/migration/migration_generator.rb
|
207
|
+
- lib/generators/stormpath/rails/templates/stormpath.yml
|
208
|
+
- lib/generators/stormpath/rails/templates/update_account_model.rb
|
190
209
|
- lib/stormpath-rails.rb
|
191
210
|
- lib/stormpath/rails/account.rb
|
192
211
|
- lib/stormpath/rails/client.rb
|
193
212
|
- lib/stormpath/rails/config.rb
|
194
213
|
- lib/stormpath/rails/version.rb
|
195
214
|
- spec/fixtures/config/stormpath.yml
|
196
|
-
- spec/generators/
|
215
|
+
- spec/generators/install_generator_spec.rb
|
216
|
+
- spec/generators/migration_generator_spec.rb
|
197
217
|
- spec/integration/active_record_spec.rb
|
198
218
|
- spec/integration/mongoid_spec.rb
|
199
219
|
- spec/spec_helper.rb
|
@@ -227,7 +247,8 @@ specification_version: 3
|
|
227
247
|
summary: Stormpath SDK API Wrapper
|
228
248
|
test_files:
|
229
249
|
- spec/fixtures/config/stormpath.yml
|
230
|
-
- spec/generators/
|
250
|
+
- spec/generators/install_generator_spec.rb
|
251
|
+
- spec/generators/migration_generator_spec.rb
|
231
252
|
- spec/integration/active_record_spec.rb
|
232
253
|
- spec/integration/mongoid_spec.rb
|
233
254
|
- spec/spec_helper.rb
|
@@ -1,9 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
require "generators/stormpath/rails/install/install_generator"
|
3
|
-
|
4
|
-
describe Stormpath::Rails::Generators::InstallGenerator do
|
5
|
-
it "creates a configuration file" do
|
6
|
-
subject.should_receive(:create_file).with("config/stormpath.yml", kind_of(String))
|
7
|
-
subject.create_initializer_file
|
8
|
-
end
|
9
|
-
end
|