devise_meteor 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.travis.yml +4 -0
  4. data/CODE_OF_CONDUCT.md +13 -0
  5. data/Gemfile +16 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +78 -0
  8. data/Rakefile +7 -0
  9. data/app/models/devise_meteor/meteor_profile.rb +12 -0
  10. data/app/models/devise_meteor/meteor_service.rb +16 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +7 -0
  13. data/devise_meteor.gemspec +37 -0
  14. data/lib/devise/strategies/meteor.rb +92 -0
  15. data/lib/devise_meteor/concerns/meteor_user_model.rb +148 -0
  16. data/lib/devise_meteor/engine.rb +10 -0
  17. data/lib/devise_meteor/railtie.rb +7 -0
  18. data/lib/devise_meteor/strategies/encrypter.rb +15 -0
  19. data/lib/devise_meteor/strategies/hasher.rb +91 -0
  20. data/lib/devise_meteor/strategies/strategy.rb +92 -0
  21. data/lib/devise_meteor/version.rb +3 -0
  22. data/lib/devise_meteor.rb +37 -0
  23. data/lib/generators/devise_meteor/install_generator.rb +16 -0
  24. data/lib/generators/templates/meteor_initializer.rb +12 -0
  25. data/spec/factories/users.rb +19 -0
  26. data/spec/models/meteor_authentication_spec.rb +261 -0
  27. data/spec/rails_helper.rb +72 -0
  28. data/spec/spec_helper.rb +92 -0
  29. data/spec/support/api_macros.rb +30 -0
  30. data/spec/support/controller_macros.rb +18 -0
  31. data/spec/support/devise_macros.rb +58 -0
  32. data/spec/support/omniauth_macros.rb +44 -0
  33. data/spec/support/request_macros.rb +13 -0
  34. data/spec/test_app/README.rdoc +3 -0
  35. data/spec/test_app/Rakefile +6 -0
  36. data/spec/test_app/app/assets/javascripts/application.js +13 -0
  37. data/spec/test_app/app/assets/stylesheets/application.css +15 -0
  38. data/spec/test_app/app/controllers/application_controller.rb +5 -0
  39. data/spec/test_app/app/controllers/products_controller.rb +89 -0
  40. data/spec/test_app/app/helpers/application_helper.rb +2 -0
  41. data/spec/test_app/app/models/user.rb +43 -0
  42. data/spec/test_app/app/views/layouts/application.html.erb +14 -0
  43. data/spec/test_app/app/views/products/_form.html.erb +29 -0
  44. data/spec/test_app/app/views/products/edit.html.erb +6 -0
  45. data/spec/test_app/app/views/products/index.html.erb +33 -0
  46. data/spec/test_app/app/views/products/new.html.erb +5 -0
  47. data/spec/test_app/app/views/products/show.html.erb +25 -0
  48. data/spec/test_app/bin/bundle +3 -0
  49. data/spec/test_app/bin/rails +4 -0
  50. data/spec/test_app/bin/rake +4 -0
  51. data/spec/test_app/bin/setup +29 -0
  52. data/spec/test_app/config/application.rb +28 -0
  53. data/spec/test_app/config/boot.rb +5 -0
  54. data/spec/test_app/config/environment.rb +5 -0
  55. data/spec/test_app/config/environments/development.rb +38 -0
  56. data/spec/test_app/config/environments/production.rb +77 -0
  57. data/spec/test_app/config/environments/test.rb +45 -0
  58. data/spec/test_app/config/initializers/assets.rb +11 -0
  59. data/spec/test_app/config/initializers/backtrace_silencers.rb +7 -0
  60. data/spec/test_app/config/initializers/cookies_serializer.rb +3 -0
  61. data/spec/test_app/config/initializers/devise.rb +268 -0
  62. data/spec/test_app/config/initializers/filter_parameter_logging.rb +4 -0
  63. data/spec/test_app/config/initializers/inflections.rb +16 -0
  64. data/spec/test_app/config/initializers/mime_types.rb +4 -0
  65. data/spec/test_app/config/initializers/secret_token.rb +3 -0
  66. data/spec/test_app/config/initializers/session_store.rb +3 -0
  67. data/spec/test_app/config/initializers/wrap_parameters.rb +9 -0
  68. data/spec/test_app/config/locales/en.yml +23 -0
  69. data/spec/test_app/config/mongoid.yml +80 -0
  70. data/spec/test_app/config/routes.rb +5 -0
  71. data/spec/test_app/config/secrets.yml +22 -0
  72. data/spec/test_app/config.ru +4 -0
  73. data/spec/test_app/lib/tasks/cucumber.rake +65 -0
  74. data/spec/test_app/log/test.log +23511 -0
  75. data/spec/test_app/public/404.html +67 -0
  76. data/spec/test_app/public/422.html +67 -0
  77. data/spec/test_app/public/500.html +66 -0
  78. data/spec/test_app/public/favicon.ico +0 -0
  79. metadata +350 -0
@@ -0,0 +1,72 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV['RAILS_ENV'] ||= 'test'
3
+ require File.expand_path("../test_app/config/environment", __FILE__)
4
+ # Prevent database truncation if the environment is production
5
+ abort("The Rails environment is running in production mode!") if Rails.env.production?
6
+ require 'spec_helper'
7
+ require 'rspec/rails'
8
+ require 'factory_girl_rails'
9
+ require 'devise_meteor'
10
+ require 'capybara/rspec'
11
+ require 'database_cleaner'
12
+ require 'faker'
13
+
14
+ # Add additional requires below this line. Rails is not loaded until this point!
15
+
16
+ # Requires supporting ruby files with custom matchers and macros, etc, in
17
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
18
+ # run as spec files by default. This means that files in spec/support that end
19
+ # in _spec.rb will both be required and run as specs, causing the specs to be
20
+ # run twice. It is recommended that you do not name files matching this glob to
21
+ # end with _spec.rb. You can configure this pattern with the --pattern
22
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
23
+ #
24
+ # The following line is provided for convenience purposes. It has the downside
25
+ # of increasing the boot-up time by auto-requiring all files in the support
26
+ # directory. Alternatively, in the individual `*_spec.rb` files, manually
27
+ # require only the support files necessary.
28
+ #
29
+ Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
30
+
31
+ RSpec.configure do |config|
32
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
33
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
34
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
35
+ # examples within a transaction, remove the following line or assign false
36
+ # instead of true.
37
+
38
+ config.mock_with :rspec
39
+ config.include FactoryGirl::Syntax::Methods
40
+
41
+ config.include DeviseMeteor::Engine.routes.url_helpers
42
+ # RSpec Rails can automatically mix in different behaviours to your tests
43
+ # based on their file location, for example enabling you to call `get` and
44
+ # `post` in specs under `spec/controllers`.
45
+ #
46
+ # You can disable this behaviour by removing the line below, and instead
47
+ # explicitly tag your specs with their type, e.g.:
48
+ #
49
+ # RSpec.describe UsersController, :type => :controller do
50
+ # # ...
51
+ # end
52
+ #
53
+ # The different available types are documented in the features, such as in
54
+ # https://relishapp.com/rspec/rspec-rails/docs
55
+ config.infer_spec_type_from_file_location!
56
+
57
+ # Clean/Reset Mongoid DB prior to running the tests
58
+
59
+ config.before(:suite) do
60
+ DatabaseCleaner[:mongoid].strategy = :truncation
61
+ end
62
+
63
+ config.before(:each) do
64
+ #Mongoid::Config.purge!
65
+ DatabaseCleaner.start
66
+ end
67
+
68
+ config.after(:each) do
69
+ DatabaseCleaner.clean
70
+ end
71
+
72
+ end
@@ -0,0 +1,92 @@
1
+ # This file was generated by the `rails generate rspec:install` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+ =begin
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Allows RSpec to persist some state between runs in order to support
54
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
55
+ # you configure your source control system to ignore this file.
56
+ config.example_status_persistence_file_path = "spec/examples.txt"
57
+
58
+ # Limits the available syntax to the non-monkey patched syntax that is
59
+ # recommended. For more details, see:
60
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
61
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
62
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
63
+ config.disable_monkey_patching!
64
+
65
+ # Many RSpec users commonly either run the entire suite or an individual
66
+ # file, and it's useful to allow more verbose output when running an
67
+ # individual spec file.
68
+ if config.files_to_run.one?
69
+ # Use the documentation formatter for detailed output,
70
+ # unless a formatter has already been configured
71
+ # (e.g. via a command-line flag).
72
+ config.default_formatter = 'doc'
73
+ end
74
+
75
+ # Print the 10 slowest examples and example groups at the
76
+ # end of the spec run, to help surface which specs are running
77
+ # particularly slow.
78
+ config.profile_examples = 10
79
+
80
+ # Run specs in random order to surface order dependencies. If you find an
81
+ # order dependency and want to debug it, you can fix the order by providing
82
+ # the seed, which is printed after each run.
83
+ # --seed 1234
84
+ config.order = :random
85
+
86
+ # Seed global randomization in this process using the `--seed` CLI option.
87
+ # Setting this allows you to use `--seed` to deterministically reproduce
88
+ # test failures related to randomization by passing the same `--seed` value
89
+ # as the one that triggered the failure.
90
+ Kernel.srand config.seed
91
+ =end
92
+ end
@@ -0,0 +1,30 @@
1
+ module ApiMacros
2
+
3
+ USER_TOKEN_FIELD = 'X-User-Token'
4
+
5
+ def request_with_user_session(method, path, params={}, headers={})
6
+ headers.merge!(USER_TOKEN_FIELD => retrieve_access_token)
7
+ send(method, path, params: params, headers: headers)
8
+ end
9
+
10
+ def get_with_token(path, params={}, headers={})
11
+ headers.merge!(USER_TOKEN_FIELD => @user.authentication_token)
12
+ get path, params: params, headers: headers
13
+ end
14
+
15
+ # make a POST with
16
+ def post_with_token(path, params={}, headers={})
17
+ headers.merge!(USER_TOKEN_FIELD => @user.authentication_token)
18
+ post path, params: params, headers: headers
19
+ end
20
+
21
+ # stub out authenticate_request
22
+ def stub_request
23
+ ApplicationController.any_instance.stub(:authenticate_request) { true }
24
+ end
25
+
26
+ # Rails.application shortcut
27
+ def app
28
+ Rails.application
29
+ end
30
+ end
@@ -0,0 +1,18 @@
1
+ module ControllerMacros
2
+
3
+ # This method uses warden
4
+ # sign in a given user or creates one automatically
5
+ # nil allows to force not logged in user
6
+ def sign_up_and_in(user_attributes=FactoryGirl.attributes_for(:user))
7
+
8
+ if user_attributes
9
+ create_user(user_attributes)
10
+ allow(request.env['warden']).to receive(:authenticate!).and_return(@user)
11
+ allow(controller).to receive(:current_user).and_return(@user)
12
+ else
13
+ allow(request.env['warden']).to receive(:authenticate!).and_throw(:warden, {:scope => :user})
14
+ allow(controller).to receive(:current_user).and_return(nil)
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,58 @@
1
+ module DeviseMacros
2
+
3
+ # map_devise_user, map_devise_admin is usually used in ControllerTests to tell devise
4
+ # which controller scope should be used
5
+ # (you can have more than one e.g. :admin, :premium)
6
+ # use this if you don't sign in any user, but need basic devise functionality
7
+
8
+ def map_devise_user
9
+ @request.env["devise.mapping"] = Devise.mappings[:user]
10
+ end
11
+
12
+ def map_devise_admin
13
+ @request.env["devise.mapping"] = Devise.mappings[:admin]
14
+ end
15
+
16
+ # creates an user and signs out
17
+ # assigns @user
18
+
19
+ def create_user(user_attributes=nil)
20
+
21
+ map_devise_user
22
+
23
+ if user_attributes.nil?
24
+ user_attributes = FactoryGirl.attributes_for :user
25
+ end
26
+
27
+ @user_attr = user_attributes
28
+ @user = User.new(@user_attr)
29
+ @user.skip_confirmation!
30
+ @user.save!
31
+
32
+ sign_out @user
33
+ end
34
+
35
+ # creates and login a user
36
+ # assigns @user
37
+
38
+ def login_user(user=nil)
39
+ map_devise_user
40
+ @user = user || FactoryGirl.create(:user)
41
+ # or set a confirmed_at inside the factory.
42
+ # Only necessary if you are using the "confirmable" module
43
+ @user.confirm
44
+ sign_in @user
45
+ end
46
+
47
+
48
+ # creates an admin and signs in
49
+ # assigns @admin
50
+
51
+ def login_admin(admin=nil)
52
+ map_devise_admin
53
+ @admin = admin || FactoryGirl.create(:admin)
54
+ sign_in @admin
55
+ end
56
+
57
+
58
+ end
@@ -0,0 +1,44 @@
1
+ module OmniauthMacros
2
+
3
+ def setup_for_login(provider)
4
+ OmniAuth.config.mock_auth[provider.to_sym] = send("params_#{provider}")
5
+ end
6
+
7
+ # create a mock response for omniauth providers
8
+ def mock_omniauth(provider, test_mode=true)
9
+
10
+ # call method with mock values and attributes for given provider
11
+ params_provider = send("params_#{provider}")
12
+
13
+ # deactivate test_mode
14
+ OmniAuth.config.test_mode = test_mode ? true : false
15
+
16
+ #deliver omniauth mock credentials
17
+ OmniAuth.config.add_mock(provider.to_sym, params_provider)
18
+ end
19
+
20
+ def params_facebook
21
+ {:info => {email: Faker::Internet.email},
22
+ user_info: {name: Faker::Name.name,
23
+ image: '',
24
+ email: Faker::Internet.email},
25
+ uid: "#{Faker::Number.number(10)}",
26
+ provider: 'facebook',
27
+ credentials: {token: 'token'}}
28
+ end
29
+
30
+ def params_twitter
31
+ {:provider => :twitter,
32
+ :uuid => '1234',
33
+ :credentials => {:token => "1234567890134567890"},
34
+ :info => {email: Faker::Internet.email}
35
+ }
36
+ end
37
+
38
+ def params_github
39
+ {'provider' => 'github',
40
+ 'uid' => "#{Faker::Number.number(10)}"
41
+ }
42
+ end
43
+
44
+ end
@@ -0,0 +1,13 @@
1
+ module RequestMacros
2
+
3
+ # login a given user by passing a TOKEN
4
+ def login(user)
5
+ post_via_redirect user_session_path, headers: {'X-User-Token' => user.authentication_token}
6
+ end
7
+
8
+ # logout a given user by passing a TOKEN
9
+ def logout(user)
10
+ post_via_redirect destroy_user_session_path, headers: {'X-User-Token' => user.authentication_token}
11
+ end
12
+
13
+ end
@@ -0,0 +1,3 @@
1
+ == README
2
+
3
+ This is the demo app.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,89 @@
1
+ class ProductsController < ApplicationController
2
+ # GET /products
3
+ # GET /products.json
4
+ def index
5
+ @products = User.all
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.json { render json: @products }
10
+ end
11
+ end
12
+
13
+ # GET /products/1
14
+ # GET /products/1.json
15
+ def show
16
+ @product = User.find(params[:id])
17
+
18
+ respond_to do |format|
19
+ format.html # show.html.erb
20
+ format.json { render json: @product }
21
+ end
22
+ end
23
+
24
+ # GET /products/new
25
+ # GET /products/new.json
26
+ def new
27
+ @product = User.new
28
+
29
+ respond_to do |format|
30
+ format.html # new.html.erb
31
+ format.json { render json: @product }
32
+ end
33
+ end
34
+
35
+ # GET /products/1/edit
36
+ def edit
37
+ @product = User.find(params[:id])
38
+ end
39
+
40
+ # POST /products
41
+ # POST /products.json
42
+ def create
43
+ @product = User.new(product_params)
44
+
45
+ respond_to do |format|
46
+ if @product.save
47
+ format.html { redirect_to @product, notice: 'User was successfully created.' }
48
+ format.json { render json: @product, status: :created, location: @product }
49
+ else
50
+ format.html { render action: "new" }
51
+ format.json { render json: @product.errors, status: :unprocessable_entity }
52
+ end
53
+ end
54
+ end
55
+
56
+ # PUT /products/1
57
+ # PUT /products/1.json
58
+ def update
59
+ @product = User.find(params[:id])
60
+
61
+ respond_to do |format|
62
+ if @product.update(product_params)
63
+ format.html { redirect_to @product, notice: 'User was successfully updated.' }
64
+ format.json { head :no_content }
65
+ else
66
+ format.html { render action: 'edit' }
67
+ format.json { render json: @product.errors, status: :unprocessable_entity }
68
+ end
69
+ end
70
+ end
71
+
72
+ # DELETE /products/1
73
+ # DELETE /products/1.json
74
+ def destroy
75
+ @product = User.find(params[:id])
76
+ @product.destroy
77
+
78
+ respond_to do |format|
79
+ format.html { redirect_to products_url }
80
+ format.json { head :no_content }
81
+ end
82
+ end
83
+
84
+ private
85
+
86
+ def product_params
87
+ params.require(:product).permit(:product_title, :in_stock, :amount, :net_price, :units, :unit, :sku)
88
+ end
89
+ end