diff --git a/Gemfile b/Gemfile index 3ba7fa9..d4dab7a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,9 +1,8 @@ source 'https://rubygems.org' -ruby '2.2.3' +ruby '2.3.0' -gem 'rails', '4.2.4' -gem 'rails-api' +gem 'rails', '>= 5.0.0.beta1.1', '< 5.1' gem 'warden' gem 'active_model_serializers', github: 'rails-api/active_model_serializers' @@ -12,7 +11,7 @@ gem 'pundit' gem 'apipie-rails' # Primegap Gems -gem 'primegap-core', github: 'primegap/primegap-core', branch: 'master' +gem 'primegap-core', path: '../primegap-core' # github: 'primegap/primegap-core', branch: 'master' group :production do gem 'puma' @@ -32,5 +31,9 @@ group :test do end group :development, :test do - gem 'rspec-rails', '~> 3.3' + gem 'rspec-expectations', github: 'rspec/rspec-expectations', branch: 'master' + gem 'rspec-mocks', github: 'rspec/rspec-mocks', branch: 'master' + gem 'rspec-support', github: 'rspec/rspec-support', branch: 'master' + gem 'rspec-core', github: 'rspec/rspec-core', branch: 'master' + gem 'rspec-rails', github: 'rspec/rspec-rails', branch: 'master' end diff --git a/Gemfile.lock b/Gemfile.lock index b117fa7..3258cc9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,165 +1,243 @@ -GIT - remote: git://github.com/primegap/primegap-core.git - revision: dbf715b0c119e0fcb3e96a7641539016341bd68c - branch: master - specs: - primegap-core (0.1.0) - actionmailer (~> 4.2.4) - activerecord (~> 4.2.4) - bcrypt (~> 3.1.7) - has_secure_token - GIT remote: git://github.com/rails-api/active_model_serializers.git - revision: efe5128a2e6b8578d81bc7a807ace427c0b4d847 + revision: 0edf48845bb385dbb316f92bf390068f1fba248d specs: - active_model_serializers (0.10.0.rc3) + active_model_serializers (0.10.0.rc4) actionpack (>= 4.0) activemodel (>= 4.0) railties (>= 4.0) +GIT + remote: git://github.com/rspec/rspec-core.git + revision: e9b99468cbfa45d2c0f38e69a0c9c9184814e327 + branch: master + specs: + rspec-core (3.5.0.pre) + rspec-support (= 3.5.0.pre) + +GIT + remote: git://github.com/rspec/rspec-expectations.git + revision: 4c1856b5155f14b4fa5f2c623f2e3fe92bbd1463 + branch: master + specs: + rspec-expectations (3.5.0.pre) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (= 3.5.0.pre) + +GIT + remote: git://github.com/rspec/rspec-mocks.git + revision: 2fcdbaee682efc35c146c9f713c079356ca3ec6e + branch: master + specs: + rspec-mocks (3.5.0.pre) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (= 3.5.0.pre) + +GIT + remote: git://github.com/rspec/rspec-rails.git + revision: f37065600822e49df993e58e86b07d54e4af3fd8 + branch: master + specs: + rspec-rails (3.5.0.pre) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec-core (= 3.5.0.pre) + rspec-expectations (= 3.5.0.pre) + rspec-mocks (= 3.5.0.pre) + rspec-support (= 3.5.0.pre) + +GIT + remote: git://github.com/rspec/rspec-support.git + revision: 4b938ec512d2fbee945913afbb957b510244ecb3 + branch: master + specs: + rspec-support (3.5.0.pre) + +PATH + remote: ../primegap-core + specs: + primegap-core (0.1.0) + actionmailer (>= 5.0.0.beta1.1) + activerecord (>= 5.0.0.beta1.1) + bcrypt (~> 3.1.7) + railties (>= 5.0.0.beta1.1) + GEM remote: https://rubygems.org/ specs: - actionmailer (4.2.4) - actionpack (= 4.2.4) - actionview (= 4.2.4) - activejob (= 4.2.4) + actioncable (5.0.0.beta1.1) + actionpack (= 5.0.0.beta1.1) + celluloid (~> 0.17.2) + coffee-rails (~> 4.1.0) + em-hiredis (~> 0.3.0) + faye-websocket (~> 0.10.0) + redis (~> 3.0) + websocket-driver (~> 0.6.1) + actionmailer (5.0.0.beta1.1) + actionpack (= 5.0.0.beta1.1) + actionview (= 5.0.0.beta1.1) + activejob (= 5.0.0.beta1.1) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.4) - actionview (= 4.2.4) - activesupport (= 4.2.4) - rack (~> 1.6) - rack-test (~> 0.6.2) + actionpack (5.0.0.beta1.1) + actionview (= 5.0.0.beta1.1) + activesupport (= 5.0.0.beta1.1) + rack (~> 2.x) + rack-test (~> 0.6.3) rails-dom-testing (~> 1.0, >= 1.0.5) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.4) - activesupport (= 4.2.4) + actionview (5.0.0.beta1.1) + activesupport (= 5.0.0.beta1.1) builder (~> 3.1) erubis (~> 2.7.0) rails-dom-testing (~> 1.0, >= 1.0.5) rails-html-sanitizer (~> 1.0, >= 1.0.2) - activejob (4.2.4) - activesupport (= 4.2.4) - globalid (>= 0.3.0) - activemodel (4.2.4) - activesupport (= 4.2.4) + activejob (5.0.0.beta1.1) + activesupport (= 5.0.0.beta1.1) + globalid (>= 0.3.6) + activemodel (5.0.0.beta1.1) + activesupport (= 5.0.0.beta1.1) builder (~> 3.1) - activerecord (4.2.4) - activemodel (= 4.2.4) - activesupport (= 4.2.4) - arel (~> 6.0) - activesupport (4.2.4) + activerecord (5.0.0.beta1.1) + activemodel (= 5.0.0.beta1.1) + activesupport (= 5.0.0.beta1.1) + arel (~> 7.0) + activesupport (5.0.0.beta1.1) + concurrent-ruby (~> 1.0) i18n (~> 0.7) json (~> 1.7, >= 1.7.7) + method_source minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) apipie-rails (0.3.5) json - arel (6.0.3) + arel (7.0.0) bcrypt (3.1.10) builder (3.2.2) - codeclimate-test-reporter (0.4.7) + celluloid (0.17.3) + celluloid-essentials + celluloid-extras + celluloid-fsm + celluloid-pool + celluloid-supervision + timers (>= 4.1.1) + celluloid-essentials (0.20.5) + timers (>= 4.1.1) + celluloid-extras (0.20.5) + timers (>= 4.1.1) + celluloid-fsm (0.20.5) + timers (>= 4.1.1) + celluloid-pool (0.20.5) + timers (>= 4.1.1) + celluloid-supervision (0.20.5) + timers (>= 4.1.1) + codeclimate-test-reporter (0.4.8) simplecov (>= 0.7.1, < 1.0.0) + coffee-rails (4.1.1) + coffee-script (>= 2.2.0) + railties (>= 4.0.0, < 5.1.x) + coffee-script (2.4.1) + coffee-script-source + execjs + coffee-script-source (1.10.0) + concurrent-ruby (1.0.0) diff-lcs (1.2.5) docile (1.1.5) + em-hiredis (0.3.1) + eventmachine (~> 1.0) + hiredis (~> 0.6.0) erubis (2.7.0) + eventmachine (1.0.9.1) + execjs (2.6.0) + faye-websocket (0.10.2) + eventmachine (>= 0.12.0) + websocket-driver (>= 0.5.1) globalid (0.3.6) activesupport (>= 4.1.0) - has_secure_token (1.0.0) - activerecord (>= 3.0) + hiredis (0.6.1) + hitimes (1.2.3) i18n (0.7.0) json (1.8.3) loofah (2.0.3) nokogiri (>= 1.5.9) mail (2.6.3) mime-types (>= 1.16, < 3) - mime-types (2.6.2) - mini_portile (0.6.2) - minitest (5.8.2) - newrelic_rpm (3.13.2.302) - nokogiri (1.6.6.2) - mini_portile (~> 0.6.0) - pg (0.18.3) - puma (2.15.3) - pundit (1.0.1) + method_source (0.8.2) + mime-types (2.99) + mini_portile2 (2.0.0) + minitest (5.8.4) + newrelic_rpm (3.14.2.312) + nokogiri (1.6.7.2) + mini_portile2 (~> 2.0.0.rc2) + pg (0.18.4) + puma (2.16.0) + pundit (1.1.0) activesupport (>= 3.0.0) - rack (1.6.4) + rack (2.0.0.alpha) + json rack-test (0.6.3) rack (>= 1.0) - rails (4.2.4) - actionmailer (= 4.2.4) - actionpack (= 4.2.4) - actionview (= 4.2.4) - activejob (= 4.2.4) - activemodel (= 4.2.4) - activerecord (= 4.2.4) - activesupport (= 4.2.4) + rails (5.0.0.beta1.1) + actioncable (= 5.0.0.beta1.1) + actionmailer (= 5.0.0.beta1.1) + actionpack (= 5.0.0.beta1.1) + actionview (= 5.0.0.beta1.1) + activejob (= 5.0.0.beta1.1) + activemodel (= 5.0.0.beta1.1) + activerecord (= 5.0.0.beta1.1) + activesupport (= 5.0.0.beta1.1) bundler (>= 1.3.0, < 2.0) - railties (= 4.2.4) - sprockets-rails - rails-api (0.4.0) - actionpack (>= 3.2.11) - railties (>= 3.2.11) + railties (= 5.0.0.beta1.1) + sprockets-rails (>= 2.0.0) rails-deprecated_sanitizer (1.0.3) activesupport (>= 4.2.0.alpha) rails-dom-testing (1.0.7) activesupport (>= 4.2.0.beta, < 5.0) nokogiri (~> 1.6.0) rails-deprecated_sanitizer (>= 1.0.1) - rails-html-sanitizer (1.0.2) + rails-html-sanitizer (1.0.3) loofah (~> 2.0) rails_12factor (0.0.3) rails_serve_static_assets rails_stdout_logging - rails_serve_static_assets (0.0.4) + rails_serve_static_assets (0.0.5) rails_stdout_logging (0.0.4) - railties (4.2.4) - actionpack (= 4.2.4) - activesupport (= 4.2.4) + railties (5.0.0.beta1.1) + actionpack (= 5.0.0.beta1.1) + activesupport (= 5.0.0.beta1.1) + method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (10.4.2) - rspec-core (3.3.2) - rspec-support (~> 3.3.0) - rspec-expectations (3.3.1) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.3.0) - rspec-mocks (3.3.2) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.3.0) - rspec-rails (3.3.3) - actionpack (>= 3.0, < 4.3) - activesupport (>= 3.0, < 4.3) - railties (>= 3.0, < 4.3) - rspec-core (~> 3.3.0) - rspec-expectations (~> 3.3.0) - rspec-mocks (~> 3.3.0) - rspec-support (~> 3.3.0) - rspec-support (3.3.0) - shoulda-matchers (3.0.1) + rake (10.5.0) + redis (3.2.2) + shoulda-matchers (3.1.1) activesupport (>= 4.0.0) - simplecov (0.10.0) + simplecov (0.11.1) docile (~> 1.1.0) json (~> 1.8) simplecov-html (~> 0.10.0) simplecov-html (0.10.0) - spring (1.4.0) - sprockets (3.4.0) + spring (1.6.2) + sprockets (3.5.2) + concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (2.3.3) - actionpack (>= 3.0) - activesupport (>= 3.0) - sprockets (>= 2.8, < 4.0) + sprockets-rails (3.0.1) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) sqlite3 (1.3.11) thor (0.19.1) thread_safe (0.3.5) + timers (4.1.1) + hitimes tzinfo (1.2.2) thread_safe (~> 0.1) - warden (1.2.3) + warden (1.2.6) rack (>= 1.0) + websocket-driver (0.6.3) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.2) PLATFORMS ruby @@ -173,14 +251,17 @@ DEPENDENCIES primegap-core! puma pundit - rails (= 4.2.4) - rails-api + rails (>= 5.0.0.beta1.1, < 5.1) rails_12factor - rspec-rails (~> 3.3) + rspec-core! + rspec-expectations! + rspec-mocks! + rspec-rails! + rspec-support! shoulda-matchers spring sqlite3 warden BUNDLED WITH - 1.10.6 + 1.11.2 diff --git a/app/controllers/concerns/warden_helper.rb b/app/controllers/concerns/warden_helper.rb index 82c8a25..1ab07c3 100644 --- a/app/controllers/concerns/warden_helper.rb +++ b/app/controllers/concerns/warden_helper.rb @@ -2,8 +2,6 @@ module WardenHelper extend ActiveSupport::Concern included do - helper_method :warden, :current_user - prepend_before_action :authenticate! end diff --git a/bin/rails b/bin/rails index 62687aa..5191e69 100755 --- a/bin/rails +++ b/bin/rails @@ -1,8 +1,4 @@ #!/usr/bin/env ruby -begin - load File.expand_path('../spring', __FILE__) -rescue LoadError -end APP_PATH = File.expand_path('../../config/application', __FILE__) require_relative '../config/boot' require 'rails/commands' diff --git a/bin/rake b/bin/rake index 2e9ece4..1724048 100755 --- a/bin/rake +++ b/bin/rake @@ -1,8 +1,4 @@ #!/usr/bin/env ruby -begin - load File.expand_path('../spring', __FILE__) -rescue LoadError -end require_relative '../config/boot' require 'rake' Rake.application.run diff --git a/bin/setup b/bin/setup index eb347f9..589bee8 100755 --- a/bin/setup +++ b/bin/setup @@ -1,29 +1,34 @@ #!/usr/bin/env ruby require 'pathname' +require 'fileutils' +include FileUtils # path to your application root. APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) -Dir.chdir APP_ROOT do +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do # This script is a starting point to setup your application. - # Add necessary setup steps to this file: + # Add necessary setup steps to this file. puts '== Installing dependencies ==' - system 'gem install bundler --conservative' - system 'bundle check || bundle install' + system! 'gem install bundler --conservative' + system('bundle check') or system!('bundle install') # puts "\n== Copying sample files ==" - # unless File.exist?("config/database.yml") - # system "cp config/database.yml.sample config/database.yml" + # unless File.exist?('config/database.yml') + # cp 'config/database.yml.sample', 'config/database.yml' # end puts "\n== Preparing database ==" - system 'bin/rake db:setup' + system! 'bin/rails db:setup' puts "\n== Removing old logs and tempfiles ==" - system 'rm -f log/*' - system 'rm -rf tmp/cache' + system! 'bin/rails log:clear tmp:clear' puts "\n== Restarting application server ==" - system 'touch tmp/restart.txt' + system! 'bin/rails restart' end diff --git a/bin/update b/bin/update new file mode 100755 index 0000000..9851923 --- /dev/null +++ b/bin/update @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +chdir APP_ROOT do + # This script is a way to update your development environment automatically. + # Add necessary update steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system 'bundle check' or system! 'bundle install' + + puts "\n== Updating database ==" + system! 'bin/rails db:migrate' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/config/application.rb b/config/application.rb index 72a15ec..ae41ac4 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,44 +1,15 @@ require File.expand_path('../boot', __FILE__) -require 'rails' -# Pick the frameworks you want: -require 'active_model/railtie' -require 'active_job/railtie' -require 'active_record/railtie' -require 'action_controller/railtie' -require 'action_mailer/railtie' +require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) -CORS_ALLOW_ORIGIN = '*' -CORS_ALLOW_METHODS = %w(GET POST PUT DELETE OPTIONS).join(',') -CORS_ALLOW_HEADERS = %w(Content-Type Accept X-User-Email X-Auth-Token).join(',') - -module Primegap - module Api - class Application < Rails::Application - # Settings in config/environments/* take precedence over those specified here. - # Application configuration should go into files in config/initializers - # -- all .rb files in that directory are automatically loaded. - - # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. - # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. - # config.time_zone = 'Central Time (US & Canada)' - - # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. - # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] - # config.i18n.default_locale = :de - - # Do not swallow errors in after_commit/after_rollback callbacks. - config.active_record.raise_in_transactional_callbacks = true - - config.action_dispatch.default_headers = { - 'Access-Control-Allow-Origin' => CORS_ALLOW_ORIGIN, - 'Access-Control-Allow-Methods' => CORS_ALLOW_METHODS, - 'Access-Control-Allow-Headers' => CORS_ALLOW_HEADERS - } - end +module Primegap::Api + class Application < Rails::Application + # Settings in config/environments/* take precedence over those specified here. + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory are automatically loaded. end end diff --git a/config/environments/development.rb b/config/environments/development.rb index 21f675e..c9d06f3 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -9,9 +9,20 @@ # Do not eager load code on boot. config.eager_load = false - # Show full error reports and disable caching. - config.consider_all_requests_local = true - config.action_controller.perform_caching = false + # Show full error reports. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + if Rails.root.join('tmp/caching-dev.txt').exist? + config.action_controller.perform_caching = true + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => 'public, max-age=172800' + } + else + config.action_controller.perform_caching = false + config.cache_store = :null_store + end # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false @@ -22,6 +33,24 @@ # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. + config.assets.debug = true + + # Asset digests allow you to set far-future HTTP expiration dates on all assets, + # yet still be able to expire them through the digest params. + config.assets.digest = true + + # Adds additional error checking when serving assets at runtime. + # Checks for improperly declared sprockets dependencies. + # Raises helpful error messages. + config.assets.raise_runtime_errors = true + # Raises error for missing translations # config.action_view.raise_on_missing_translations = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + # config.file_watcher = ActiveSupport::EventedFileUpdateChecker end diff --git a/config/environments/production.rb b/config/environments/production.rb index 7e11ca7..21102db 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -14,20 +14,34 @@ config.consider_all_requests_local = false config.action_controller.perform_caching = true - # Enable Rack::Cache to put a simple HTTP cache in front of your application - # Add `rack-cache` to your Gemfile before enabling this. - # For large-scale production use, consider using a caching reverse proxy like - # NGINX, varnish or squid. - # config.action_dispatch.rack_cache = true - # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. - config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # Asset digests allow you to set far-future HTTP expiration dates on all assets, + # yet still be able to expire them through the digest params. + config.assets.digest = true + + # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + # Action Cable endpoint configuration + # config.action_cable.url = 'wss://example.com/cable' + # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true @@ -36,16 +50,18 @@ config.log_level = :debug # Prepend all log lines with the following tags. - # config.log_tags = [ :subdomain, :uuid ] + # config.log_tags = [ :subdomain, :request_id ] # Use a different logger for distributed setups. - # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + # require 'syslog/logger' + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') # Use a different cache store in production. # config.cache_store = :mem_cache_store - # Enable serving of images, stylesheets, and JavaScripts from an asset server. - # config.action_controller.asset_host = 'http://assets.example.com' + # Use a real queuing backend for Active Job (and separate queues per environment) + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "primegap/api_#{Rails.env}" # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. diff --git a/config/environments/test.rb b/config/environments/test.rb index 1c19f08..1f90453 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -12,9 +12,11 @@ # preloads Rails for running tests, you may have to set it to true. config.eager_load = false - # Configure static file server for tests with Cache-Control for performance. - config.serve_static_files = true - config.static_cache_control = 'public, max-age=3600' + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + 'Cache-Control' => 'public, max-age=3600' + } # Show full error reports and disable caching. config.consider_all_requests_local = true diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb new file mode 100644 index 0000000..51639b6 --- /dev/null +++ b/config/initializers/application_controller_renderer.rb @@ -0,0 +1,6 @@ +# Be sure to restart your server when you modify this file. + +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb new file mode 100644 index 0000000..01ef3e6 --- /dev/null +++ b/config/initializers/assets.rb @@ -0,0 +1,11 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = '1.0' + +# Add additional assets to the asset load path +# Rails.application.config.assets.paths << Emoji.images_path + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. +# Rails.application.config.assets.precompile += %w( search.js ) diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000..59385cd --- /dev/null +++ b/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb new file mode 100644 index 0000000..0aa786f --- /dev/null +++ b/config/initializers/cookies_serializer.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# This is a new Rails 5.0 default, so introduced as a config to ensure apps made with earlier versions of Rails aren't affected when upgrading. +Rails.application.config.action_dispatch.cookies_serializer = :marshal diff --git a/config/initializers/cors.rb b/config/initializers/cors.rb new file mode 100644 index 0000000..3b1c1b5 --- /dev/null +++ b/config/initializers/cors.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Avoid CORS issues when API is called from the frontend app. +# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests. + +# Read more: https://github.com/cyu/rack-cors + +# Rails.application.config.middleware.insert_before 0, Rack::Cors do +# allow do +# origins 'example.com' +# +# resource '*', +# headers: :any, +# methods: [:get, :post, :put, :patch, :delete, :options, :head] +# end +# end diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb new file mode 100644 index 0000000..ac033bf --- /dev/null +++ b/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb new file mode 100644 index 0000000..dc18996 --- /dev/null +++ b/config/initializers/mime_types.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf diff --git a/config/initializers/request_forgery_protection.rb b/config/initializers/request_forgery_protection.rb new file mode 100644 index 0000000..3eab78a --- /dev/null +++ b/config/initializers/request_forgery_protection.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Enable origin-checking CSRF mitigation. +Rails.application.config.action_controller.forgery_protection_origin_check = true diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb new file mode 100644 index 0000000..9d59da8 --- /dev/null +++ b/config/initializers/session_store.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +Rails.application.config.session_store :cookie_store, key: '_primegap/api_session' diff --git a/config/initializers/warden.rb b/config/initializers/warden.rb index 802db34..55ff8fa 100644 --- a/config/initializers/warden.rb +++ b/config/initializers/warden.rb @@ -2,7 +2,7 @@ Warden::Strategies.add(:authentication_token, AuthenticationTokenStrategy) -Rails.application.config.middleware.insert_after ActionDispatch::ParamsParser, Warden::Manager do |manager| +Rails.application.config.middleware.insert_after ActionDispatch::Callbacks, Warden::Manager do |manager| manager.default_strategies :authentication_token manager.failure_app = UnauthenticatedController end diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index 54961ef..bbfc396 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -1,13 +1,14 @@ # Be sure to restart your server when you modify this file. -# -# This file contains settings for ActionController::ParamsWrapper -# Enable parameter wrapping for JSON. -# ActiveSupport.on_load(:action_controller) do -# wrap_parameters format: [:json] if respond_to?(:wrap_parameters) -# end +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] +end # To enable root element in JSON for ActiveRecord objects. # ActiveSupport.on_load(:active_record) do -# self.include_root_in_json = true +# self.include_root_in_json = true # end diff --git a/config/redis/cable.yml b/config/redis/cable.yml new file mode 100644 index 0000000..0176be2 --- /dev/null +++ b/config/redis/cable.yml @@ -0,0 +1,9 @@ +# Action Cable uses Redis to administer connections, channels, and sending/receiving messages over the WebSocket. +production: + url: redis://localhost:6379/1 + +development: + url: redis://localhost:6379/2 + +test: + url: redis://localhost:6379/3 diff --git a/config/routes.rb b/config/routes.rb index fcac1ee..8293c8a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,19 +1,6 @@ Rails.application.routes.draw do - apipie - resources :customers, only: [:index, :show, :create, :update, :destroy] - resource :sessions, only: [:create, :destroy] + # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html - cors_head = proc do - [ - 204, - { - 'Content-Type' => 'text/plain', - 'Access-Control-Allow-Origin' => CORS_ALLOW_ORIGIN, - 'Access-Control-Allow-Methods' => CORS_ALLOW_METHODS, - 'Access-Control-Allow-Headers' => CORS_ALLOW_HEADERS - }, - [] - ] - end - match '/*path', to: cors_head, via: [:options, :head] + # Serve websocket cable requests in-process + # mount ActionCable.server => '/cable' end diff --git a/spec/controllers/customers_controller_spec.rb b/spec/controllers/customers_controller_spec.rb index 7828be0..e3b1723 100644 --- a/spec/controllers/customers_controller_spec.rb +++ b/spec/controllers/customers_controller_spec.rb @@ -37,7 +37,7 @@ describe 'GET #show' do it 'assigns the requested customer as @customer' do - get :show, id: customer.id, format: :json + get :show, params: { id: customer.id }, format: :json expect(assigns(:customer)).to eq(customer) expect(response).to be_success end @@ -47,31 +47,31 @@ context 'with valid params' do it 'creates a new Customer' do expect do - post :create, customer: valid_attributes, format: :json + post :create, params: { customer: valid_attributes }, format: :json end.to change(Customer, :count).by(1) end it 'assigns a newly created customer as @customer' do - post :create, customer: valid_attributes, format: :json + post :create, params: { customer: valid_attributes }, format: :json expect(assigns(:customer)).to be_a(Customer) expect(assigns(:customer)).to be_persisted expect(response).to be_success end it 'returns success status' do - post :create, customer: valid_attributes, format: :json + post :create, params: { customer: valid_attributes }, format: :json expect(response).to be_success end end context 'with invalid params' do it 'assigns a newly created but unsaved customer as @customer' do - post :create, customer: invalid_attributes, format: :json + post :create, params: { customer: invalid_attributes }, format: :json expect(assigns(:customer)).to be_a_new(Customer) end it 'returns unprocessable_entity status' do - post :create, customer: invalid_attributes, format: :json + post :create, params: { customer: invalid_attributes }, format: :json expect(response.status).to eq(422) end end @@ -83,8 +83,11 @@ { full_name: 'John F. Doe', phone: '234567890' } end + before do + put :update, params: { id: customer.id, customer: new_attributes }, format: :json + end + it 'updates the requested customer' do - put :update, id: customer.id, customer: new_attributes, format: :json customer.reload expect(customer.full_name).to eq('John F. Doe') expect(customer.first_name).to eq('John F.') @@ -93,24 +96,24 @@ end it 'assigns the requested customer as @customer' do - put :update, id: customer.id, customer: new_attributes, format: :json expect(assigns(:customer)).to eq(customer) end it 'returns success status' do - put :update, id: customer.id, customer: new_attributes, format: :json expect(response).to be_success end end context 'with invalid params' do + before do + put :update, params: { id: customer.id, customer: invalid_attributes }, format: :json + end + it 'assigns the customer as @customer' do - put :update, id: customer.id, customer: invalid_attributes, format: :json expect(assigns(:customer)).to eq(customer) end it 'returns unprocessable_entity status' do - put :update, id: customer.id, customer: invalid_attributes, format: :json expect(response.status).to eq(422) end end @@ -119,12 +122,12 @@ describe 'DELETE #destroy' do it 'destroys the requested customer' do expect do - delete :destroy, id: customer.id, format: :json + delete :destroy, params: { id: customer.id }, format: :json end.to change(Customer, :count).by(-1) end it 'redirects to the customers list' do - delete :destroy, id: customer.id, format: :json + delete :destroy, params: { id: customer.id }, format: :json expect(response.status).to eq(204) end end diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb index d594fca..106d530 100644 --- a/spec/controllers/sessions_controller_spec.rb +++ b/spec/controllers/sessions_controller_spec.rb @@ -28,20 +28,20 @@ def set_auth_headers describe 'POST #create' do context 'with valid credentials' do - before { post :create, valid_attributes, format: :json } + before { post :create, params: valid_attributes, format: :json } it { expect(response).to be_success } it { expect(parsed_response).to eq('user_email' => user.email, 'auth_token' => authentication_token.body) } end context 'with invalid credentials' do - before { post :create, invalid_attributes, format: :json } + before { post :create, params: invalid_attributes, format: :json } it { expect(response.status).to eq(401) } end context 'with missing/invalid params' do - before { post :create, foo: { bar: 'baz' }, format: :json } + before { post :create, params: { foo: { bar: 'baz' } }, format: :json } it { expect(response.status).to eq(422) } end diff --git a/spec/support/api_controller.rb b/spec/support/api_controller.rb index 5720480..e704b82 100644 --- a/spec/support/api_controller.rb +++ b/spec/support/api_controller.rb @@ -3,21 +3,21 @@ RSpec.shared_examples 'api_controller' do describe 'rescues from ActiveRecord::RecordNotFound' do context 'on GET #show' do - before { get :show, id: 'not-existing', format: :json } + before { get :show, params: { id: 'not-existing' }, format: :json } it { expect(response.status).to eq(404) } it { expect(response.body).to be_blank } end context 'on PUT #update' do - before { put :update, id: 'not-existing', format: :json } + before { put :update, params: { id: 'not-existing' }, format: :json } it { expect(response.status).to eq(404) } it { expect(response.body).to be_blank } end context 'on DELETE #destroy' do - before { delete :destroy, id: 'not-existing', format: :json } + before { delete :destroy, params: { id: 'not-existing' }, format: :json } it { expect(response.status).to eq(404) } it { expect(response.body).to be_blank } @@ -26,7 +26,7 @@ describe 'rescues from ActionController::ParameterMissing' do context 'on POST #create' do - before { post :create, wrong_params: { foo: :bar }, format: :json } + before { post :create, params: { wrong_params: { foo: :bar } }, format: :json } it { expect(response.status).to eq(422) } it { expect(response.body).to match(/error/) }