From e1038daa69575bed3460dd29c1cf2453ce2164e9 Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Mon, 9 Sep 2013 14:00:16 +0400 Subject: [PATCH 01/21] upgrade to rails 4 --- Gemfile | 9 +-- Gemfile.lock | 170 ++++++++++++++++++------------------------ config/application.rb | 6 +- 3 files changed, 76 insertions(+), 109 deletions(-) diff --git a/Gemfile b/Gemfile index 9ac62b7..b59f714 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -gem 'rails', '3.2.12' +gem 'rails', '4.0.0' gem 'rails-api' @@ -9,10 +9,9 @@ gem 'airbrake' gem 'thin' gem 'decent_exposure' gem 'active_model_serializers' -gem 'seedbank' +gem 'seedbank', github: 'james2m/seedbank' gem 'dotenv' -gem 'strong_parameters' -gem 'devise' +gem 'devise', '~> 3.1.0' group :development do gem 'letter_opener' @@ -43,7 +42,7 @@ group :test do end group :development, :staging do - gem 'api_taster', git: 'git@github.com:fredwu/api_taster.git' + # gem 'api_taster', git: 'git@github.com:fredwu/api_taster.git' end group :development, :test, :staging do diff --git a/Gemfile.lock b/Gemfile.lock index 9626d7d..8ad1368 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,57 +1,47 @@ GIT - remote: git@github.com:fredwu/api_taster.git - revision: 39b288c351fe39c301bcb0ea6136b4653f24eceb + remote: git://github.com/james2m/seedbank.git + revision: c7a272751336f0d17103028f45b88eac62cbedd7 specs: - api_taster (0.6.0) - bootstrap-sass (~> 2.1) - jquery-rails - rails (>= 3.1.0) - redcarpet - remotipart (~> 1.0) - sass-rails + seedbank (0.3.0.pre2) GEM remote: https://rubygems.org/ specs: - actionmailer (3.2.12) - actionpack (= 3.2.12) - mail (~> 2.4.4) - actionpack (3.2.12) - activemodel (= 3.2.12) - activesupport (= 3.2.12) - builder (~> 3.0.0) + actionmailer (4.0.0) + actionpack (= 4.0.0) + mail (~> 2.5.3) + actionpack (4.0.0) + activesupport (= 4.0.0) + builder (~> 3.1.0) erubis (~> 2.7.0) - journey (~> 1.0.4) - rack (~> 1.4.5) - rack-cache (~> 1.2) - rack-test (~> 0.6.1) - sprockets (~> 2.2.1) + rack (~> 1.5.2) + rack-test (~> 0.6.2) active_model_serializers (0.7.0) activemodel (>= 3.0) - activemodel (3.2.12) - activesupport (= 3.2.12) - builder (~> 3.0.0) - activerecord (3.2.12) - activemodel (= 3.2.12) - activesupport (= 3.2.12) - arel (~> 3.0.2) - tzinfo (~> 0.3.29) - activeresource (3.2.12) - activemodel (= 3.2.12) - activesupport (= 3.2.12) - activesupport (3.2.12) - i18n (~> 0.6) - multi_json (~> 1.0) + activemodel (4.0.0) + activesupport (= 4.0.0) + builder (~> 3.1.0) + activerecord (4.0.0) + activemodel (= 4.0.0) + activerecord-deprecated_finders (~> 1.0.2) + activesupport (= 4.0.0) + arel (~> 4.0.0) + activerecord-deprecated_finders (1.0.3) + activesupport (4.0.0) + i18n (~> 0.6, >= 0.6.4) + minitest (~> 4.2) + multi_json (~> 1.3) + thread_safe (~> 0.1) + tzinfo (~> 0.3.37) addressable (2.3.3) airbrake (3.1.8) activesupport builder json - arel (3.0.2) + arel (4.0.0) + atomic (1.1.13) awesome_print (1.1.0) - bcrypt-ruby (3.0.1) - bootstrap-sass (2.3.1.0) - sass (~> 3.2) + bcrypt-ruby (3.1.2) bourne (1.1.2) mocha (= 0.10.5) brakeman (1.9.3) @@ -65,7 +55,7 @@ GEM sass (~> 3.0) slim (~> 1.3.6) terminal-table (~> 1.4) - builder (3.0.4) + builder (3.1.4) bullet (4.3.1) uniform_notifier capybara (2.0.2) @@ -93,11 +83,12 @@ GEM debugger-ruby_core_source (>= 1.1.1) debugger-ruby_core_source (1.2.0) decent_exposure (2.1.0) - devise (2.2.3) + devise (3.1.0) bcrypt-ruby (~> 3.0) orm_adapter (~> 0.1) - railties (~> 3.1) - warden (~> 1.2.1) + railties (>= 3.2.6, < 5) + thread_safe (~> 0.1) + warden (~> 1.2.3) diff-lcs (1.2.1) dotenv (0.5.0) email_spec (1.4.0) @@ -128,31 +119,27 @@ GEM haml (4.0.0) tilt highline (1.6.15) - hike (1.2.1) - i18n (0.6.4) - journey (1.0.4) - jquery-rails (2.2.1) - railties (>= 3.0, < 5.0) - thor (>= 0.14, < 2.0) - json (1.7.7) + hike (1.2.3) + i18n (0.6.5) + json (1.8.0) launchy (2.2.0) addressable (~> 2.3) letter_opener (1.1.0) launchy (~> 2.2.0) listen (0.7.3) lumberjack (1.0.2) - mail (2.4.4) - i18n (>= 0.4.0) + mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) mail_safe (0.3.1) actionmailer (>= 1.3.6) metaclass (0.0.1) method_source (0.8.1) - mime-types (1.22) + mime-types (1.25) + minitest (4.7.5) mocha (0.10.5) metaclass (~> 0.0.1) - multi_json (1.7.2) + multi_json (1.8.0) nokogiri (1.5.6) orm_adapter (0.4.0) pg (0.14.1) @@ -161,24 +148,20 @@ GEM coderay (~> 1.0.5) method_source (~> 0.8) slop (~> 3.4) - rack (1.4.5) - rack-cache (1.2) - rack (>= 0.4) - rack-ssl (1.3.3) - rack + rack (1.5.2) rack-test (0.6.2) rack (>= 1.0) - rails (3.2.12) - actionmailer (= 3.2.12) - actionpack (= 3.2.12) - activerecord (= 3.2.12) - activeresource (= 3.2.12) - activesupport (= 3.2.12) - bundler (~> 1.0) - railties (= 3.2.12) - rails-api (0.0.3) - actionpack (>= 3.2.6) - railties (>= 3.2.6) + rails (4.0.0) + actionmailer (= 4.0.0) + actionpack (= 4.0.0) + activerecord (= 4.0.0) + activesupport (= 4.0.0) + bundler (>= 1.3.0, < 2.0) + railties (= 4.0.0) + sprockets-rails (~> 2.0.0) + rails-api (0.1.0) + actionpack (>= 3.2.11) + railties (>= 3.2.11) tzinfo (~> 0.3.31) rails_best_practices (1.13.4) activesupport @@ -188,19 +171,13 @@ GEM erubis i18n ruby-progressbar - railties (3.2.12) - actionpack (= 3.2.12) - activesupport (= 3.2.12) - rack-ssl (~> 1.3.2) + railties (4.0.0) + actionpack (= 4.0.0) + activesupport (= 4.0.0) rake (>= 0.8.7) - rdoc (~> 3.4) - thor (>= 0.14.6, < 2.0) - rake (10.0.4) + thor (>= 0.18.1, < 2.0) + rake (10.1.0) rb-fsevent (0.9.3) - rdoc (3.12.2) - json (~> 1.4) - redcarpet (2.2.2) - remotipart (1.0.5) rspec (2.13.0) rspec-core (~> 2.13.0) rspec-expectations (~> 2.13.0) @@ -224,11 +201,6 @@ GEM sexp_processor (~> 4.1) rubyzip (0.9.9) sass (3.2.7) - sass-rails (3.2.6) - railties (~> 3.2.0) - sass (>= 3.1.10) - tilt (~> 1.3) - seedbank (0.2.0) selenium-webdriver (2.31.0) childprocess (>= 0.2.5) multi_json (~> 1.0) @@ -246,15 +218,15 @@ GEM temple (~> 0.5.5) tilt (~> 1.3.3) slop (3.4.4) - sprockets (2.2.2) + sprockets (2.10.0) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - strong_parameters (0.2.0) - actionpack (~> 3.0) - activemodel (~> 3.0) - railties (~> 3.0) + sprockets-rails (2.0.0) + actionpack (>= 3.0) + activesupport (>= 3.0) + sprockets (~> 2.8) temple (0.5.5) terminal-table (1.4.5) thin (1.5.0) @@ -262,13 +234,15 @@ GEM eventmachine (>= 0.12.6) rack (>= 1.0.0) thor (0.18.1) - tilt (1.3.6) - treetop (1.4.12) + thread_safe (0.1.2) + atomic + tilt (1.3.7) + treetop (1.4.15) polyglot polyglot (>= 0.3.1) tzinfo (0.3.37) uniform_notifier (1.2.0) - warden (1.2.1) + warden (1.2.3) rack (>= 1.0) webmock (1.11.0) addressable (>= 2.2.7) @@ -285,14 +259,13 @@ PLATFORMS DEPENDENCIES active_model_serializers airbrake - api_taster! brakeman bullet capybara database_cleaner debugger decent_exposure - devise + devise (~> 3.1.0) dotenv email_spec factory_girl_rails @@ -302,15 +275,14 @@ DEPENDENCIES letter_opener mail_safe pg - rails (= 3.2.12) + rails (= 4.0.0) rails-api rails_best_practices rb-fsevent rspec-rails - seedbank + seedbank! shoulda-matchers simplecov - strong_parameters thin webmock zeus diff --git a/config/application.rb b/config/application.rb index 87cb8ee..ae93148 100644 --- a/config/application.rb +++ b/config/application.rb @@ -4,15 +4,11 @@ require 'active_record/railtie' require 'action_controller/railtie' require 'action_mailer/railtie' -require 'active_resource/railtie' require 'sprockets/railtie' # require "rails/test_unit/railtie" if defined?(Bundler) - # If you precompile assets before deploying to production, use this line - Bundler.require(*Rails.groups(:assets => %w(development test))) - # If you want your assets lazily compiled in production, use this line - # Bundler.require(:default, :assets, Rails.env) + Bundler.require(:default, Rails.env) end module Rails3BaseApi From 51063e24b4a5bed163f5086ba40ec79d344cf7e9 Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Mon, 9 Sep 2013 14:09:07 +0400 Subject: [PATCH 02/21] fix configuration deprecation warnings --- config/application.rb | 3 --- config/environments/development.rb | 12 ++---------- config/environments/production.rb | 4 +--- config/environments/test.rb | 8 ++------ config/initializers/devise.rb | 2 ++ 5 files changed, 7 insertions(+), 22 deletions(-) diff --git a/config/application.rb b/config/application.rb index ae93148..b3ee82f 100644 --- a/config/application.rb +++ b/config/application.rb @@ -49,9 +49,6 @@ class Application < Rails::Application # like if you have constraints or database-specific column types # config.active_record.schema_format = :sql - # We use ActiveModel::ForbiddenAttributesProtection instead - config.active_record.whitelist_attributes = false - # Enable the asset pipeline config.assets.enabled = true diff --git a/config/environments/development.rb b/config/environments/development.rb index ebf57c3..1abc73b 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -6,9 +6,6 @@ # since you don't have to restart the web server when you make code changes. config.cache_classes = false - # Log error messages when you accidentally call methods on nil. - config.whiny_nils = true - # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false @@ -22,16 +19,11 @@ # Only use best-standards-support built into browsers config.action_dispatch.best_standards_support = :builtin - # Raise exception on mass assignment protection for Active Record models - config.active_record.mass_assignment_sanitizer = :strict - - # Log the query plan for queries taking more than this (works - # with SQLite, MySQL, and PostgreSQL) - config.active_record.auto_explain_threshold_in_seconds = 0.5 - # Do not compress assets config.assets.compress = false # Expands the lines which load the assets config.assets.debug = true + + config.eager_load = false end diff --git a/config/environments/production.rb b/config/environments/production.rb index a215375..5236ecc 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -61,7 +61,5 @@ # Send deprecation notices to registered listeners config.active_support.deprecation = :notify - # Log the query plan for queries taking more than this (works - # with SQLite, MySQL, and PostgreSQL) - # config.active_record.auto_explain_threshold_in_seconds = 0.5 + config.eager_load = true end diff --git a/config/environments/test.rb b/config/environments/test.rb index eaa96f0..5bce721 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -11,9 +11,6 @@ config.serve_static_assets = true config.static_cache_control = "public, max-age=3600" - # Log error messages when you accidentally call methods on nil - config.whiny_nils = true - # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false @@ -29,9 +26,8 @@ # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test - # Raise exception on mass assignment protection for Active Record models - config.active_record.mass_assignment_sanitizer = :strict - # Print deprecation notices to the stderr config.active_support.deprecation = :stderr + + config.eager_load = false end diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 90485ff..24c4ed7 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -237,4 +237,6 @@ # When using omniauth, Devise cannot automatically set Omniauth path, # so you need to do it manually. For the users scope, it would be: # config.omniauth_path_prefix = "/my_engine/users/auth" + + config.secret_key = '1aba5cc0f0333ae917458e95386efa263e9c0452e8f16f03c77e27251387c7e412f2abdac42cc19b5ca4a160e6f793ba0693cd5aed35e332ce8e3bc57e140a86' end From 4de6a919bd39891f258bde0c0ce7dddbd29aee22 Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Mon, 9 Sep 2013 14:11:26 +0400 Subject: [PATCH 03/21] add Ac::ImplicitRender to ApplicationController --- app/controllers/application_controller.rb | 2 +- config/application.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e1c901c..3ede7ab 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,5 @@ class ApplicationController < ActionController::API - include ActionController::MimeResponds + include ActionController::MimeResponds, ActionController::ImplicitRender self.responder = ApiResponder diff --git a/config/application.rb b/config/application.rb index b3ee82f..871a4cd 100644 --- a/config/application.rb +++ b/config/application.rb @@ -61,6 +61,7 @@ class Application < Rails::Application # By default Rails API does not include the session middleware. # Add the middleware back in to application b/c it requred by Devise and Warden config.middleware.use ActionDispatch::Session::CookieStore + config.middleware.use Rack::MethodOverride # Parameter keys that are not explicitly permitted will be raised as exception config.action_controller.action_on_unpermitted_parameters = :raise From 6c504cda9619e2279e8e9ebebfbe9e0874dda980 Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Mon, 9 Sep 2013 14:18:18 +0400 Subject: [PATCH 04/21] .scoped is deprecated --- Gemfile.lock | 2 +- config/initializers/secret_token.rb | 1 + spec/controllers/posts_controller_spec.rb | 2 +- spec/controllers/user/comments_controller_spec.rb | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8ad1368..5b71fc8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -82,7 +82,7 @@ GEM debugger-linecache (1.1.2) debugger-ruby_core_source (>= 1.1.1) debugger-ruby_core_source (1.2.0) - decent_exposure (2.1.0) + decent_exposure (2.2.1) devise (3.1.0) bcrypt-ruby (~> 3.0) orm_adapter (~> 0.1) diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb index ace58ba..5cd1e8f 100644 --- a/config/initializers/secret_token.rb +++ b/config/initializers/secret_token.rb @@ -5,3 +5,4 @@ # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. Rails.application.config.secret_token = '2bcc1492fb9e2f8158a1bb5e951022317eba080b195d676d77d65f2f8a2ee751d816683e05a8ea21673219' +Rails.application.config.secret_key_base = '376a9c237816fff5b0fc1a0febd3a7929e4f114e04b6d1179fe8c85edaa0e4d492d6fadcca7c73f9543a7a' diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 5998c7d..a3fdce7 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -6,7 +6,7 @@ before do posts.stub(:find) { post } - Post.stub(:scoped) { posts } + Post.stub(:all) { posts } end describe 'GET #index' do diff --git a/spec/controllers/user/comments_controller_spec.rb b/spec/controllers/user/comments_controller_spec.rb index 6a0de93..00e988c 100644 --- a/spec/controllers/user/comments_controller_spec.rb +++ b/spec/controllers/user/comments_controller_spec.rb @@ -9,7 +9,7 @@ let(:comments) { FactoryGirl.build_list :comment, 2 } before do - controller.current_user.stub(:comments) { double(scoped: comments) } + controller.current_user.stub(:comments) { double(all: comments) } get :index, format: :json From fbeafe7088fdfc0e26090ec3289d304bf2f5eaf0 Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Mon, 9 Sep 2013 14:29:22 +0400 Subject: [PATCH 05/21] update debugger --- Gemfile.lock | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 5b71fc8..0e2705e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -75,13 +75,12 @@ GEM crack (0.3.2) daemons (1.1.9) database_cleaner (0.9.1) - debugger (1.4.0) + debugger (1.6.1) columnize (>= 0.3.1) - debugger-linecache (~> 1.1.1) - debugger-ruby_core_source (~> 1.2.0) - debugger-linecache (1.1.2) - debugger-ruby_core_source (>= 1.1.1) - debugger-ruby_core_source (1.2.0) + debugger-linecache (~> 1.2.0) + debugger-ruby_core_source (~> 1.2.3) + debugger-linecache (1.2.0) + debugger-ruby_core_source (1.2.3) decent_exposure (2.2.1) devise (3.1.0) bcrypt-ruby (~> 3.0) From 1227ec3fc681bf6de834eacf4b74102c377f968e Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Mon, 9 Sep 2013 14:55:09 +0400 Subject: [PATCH 06/21] update db schema --- db/schema.rb | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 7ab75a7..3c5fb8f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,47 +9,47 @@ # from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # -# It's strongly recommended to check this file into your version control system. +# It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(:version => 20130319140714) do +ActiveRecord::Schema.define(version: 20130319140714) do - create_table "comments", :force => true do |t| + create_table "comments", force: true do |t| t.string "title" t.string "text" t.integer "post_id" t.integer "user_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" end - add_index "comments", ["post_id"], :name => "index_comments_on_post_id" - add_index "comments", ["user_id"], :name => "index_comments_on_user_id" + add_index "comments", ["post_id"], name: "index_comments_on_post_id", using: :btree + add_index "comments", ["user_id"], name: "index_comments_on_user_id", using: :btree - create_table "posts", :force => true do |t| + create_table "posts", force: true do |t| t.string "title" t.text "text" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" end - create_table "users", :force => true do |t| - t.string "email", :default => "", :null => false - t.string "encrypted_password", :default => "", :null => false + create_table "users", force: true do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", :default => 0 + t.integer "sign_in_count", default: 0 t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" t.string "authentication_token" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at" + t.datetime "updated_at" end - add_index "users", ["authentication_token"], :name => "index_users_on_authentication_token", :unique => true - add_index "users", ["email"], :name => "index_users_on_email", :unique => true - add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true + add_index "users", ["authentication_token"], name: "index_users_on_authentication_token", unique: true, using: :btree + add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree + add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree end From d7039baea10dc54c0b8b723d9338771c984743f9 Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Mon, 9 Sep 2013 15:12:22 +0400 Subject: [PATCH 07/21] make database_cleaner actually clean db --- Gemfile.lock | 2 +- spec/spec_helper.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 0e2705e..92c4b84 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -74,7 +74,7 @@ GEM columnize (0.3.6) crack (0.3.2) daemons (1.1.9) - database_cleaner (0.9.1) + database_cleaner (1.1.1) debugger (1.6.1) columnize (>= 0.3.1) debugger-linecache (~> 1.2.0) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b63bd41..8eef23b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -32,6 +32,14 @@ ActionMailer::Base.deliveries.clear end + config.before(:each) do + DatabaseCleaner.start + end + + config.after(:each) do + DatabaseCleaner.clean + end + # Make sure we will send all requests with correct content type # config.before(type: :controller) do From f89e2d71e00936573a368a9aeb3e70437310c46d Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Mon, 9 Sep 2013 15:33:55 +0400 Subject: [PATCH 08/21] prepare test db on ci --- script/bootstrap | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/script/bootstrap b/script/bootstrap index 18667dd..61d68a1 100755 --- a/script/bootstrap +++ b/script/bootstrap @@ -72,6 +72,10 @@ def migrate_db end end +def prepare_test_db + system('bundle exec rake db:test:prepare') +end + is_ci = ARGV.shift == 'ci' setup_database_yml @@ -79,5 +83,6 @@ setup_dotenv install_bundler install_gems(is_ci ? 'development' : '') migrate_db +prepare_test_db if is_ci puts 'Everything is up to date.' From a90fa156a875ca660ac871108b5921e3262e85a7 Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Tue, 10 Sep 2013 18:33:00 +0400 Subject: [PATCH 09/21] update rbp, fix its warnings --- Gemfile.lock | 12 ++++++---- config/rails_best_practices.yml | 41 +++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 config/rails_best_practices.yml diff --git a/Gemfile.lock b/Gemfile.lock index 92c4b84..7caa1b8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -67,7 +67,7 @@ GEM xpath (~> 1.0.0) childprocess (0.3.9) ffi (~> 1.0, >= 1.0.11) - code_analyzer (0.3.1) + code_analyzer (0.4.2) sexp_processor coderay (1.0.9) colored (1.2) @@ -162,13 +162,14 @@ GEM actionpack (>= 3.2.11) railties (>= 3.2.11) tzinfo (~> 0.3.31) - rails_best_practices (1.13.4) + rails_best_practices (1.14.3) activesupport awesome_print - code_analyzer + code_analyzer (>= 0.4.2) colored erubis i18n + require_all ruby-progressbar railties (4.0.0) actionpack (= 4.0.0) @@ -177,6 +178,7 @@ GEM thor (>= 0.18.1, < 2.0) rake (10.1.0) rb-fsevent (0.9.3) + require_all (1.3.0) rspec (2.13.0) rspec-core (~> 2.13.0) rspec-expectations (~> 2.13.0) @@ -192,7 +194,7 @@ GEM rspec-core (~> 2.13.0) rspec-expectations (~> 2.13.0) rspec-mocks (~> 2.13.0) - ruby-progressbar (1.0.2) + ruby-progressbar (1.2.0) ruby2ruby (2.0.3) ruby_parser (~> 3.1) sexp_processor (~> 4.0) @@ -205,7 +207,7 @@ GEM multi_json (~> 1.0) rubyzip websocket (~> 1.0.4) - sexp_processor (4.1.5) + sexp_processor (4.3.0) shoulda-matchers (1.4.2) activesupport (>= 3.0.0) bourne (~> 1.1.2) diff --git a/config/rails_best_practices.yml b/config/rails_best_practices.yml new file mode 100644 index 0000000..21e843b --- /dev/null +++ b/config/rails_best_practices.yml @@ -0,0 +1,41 @@ +AddModelVirtualAttributeCheck: { } +AlwaysAddDbIndexCheck: { } +#CheckSaveReturnValueCheck: { } +DefaultScopeIsEvilCheck: { } +DryBundlerInCapistranoCheck: { } +#HashSyntaxCheck: { } +IsolateSeedDataCheck: { } +KeepFindersOnTheirOwnModelCheck: { } +LawOfDemeterCheck: { } +# LongLineCheck: { max_line_length: 100 } +MoveCodeIntoControllerCheck: { } +MoveCodeIntoHelperCheck: { array_count: 3 } +MoveCodeIntoModelCheck: { use_count: 2 } +MoveFinderToNamedScopeCheck: { } +MoveModelLogicIntoModelCheck: { use_count: 4 } +NeedlessDeepNestingCheck: { nested_count: 2 } +NotRescueExceptionCheck: { } +NotUseDefaultRouteCheck: { } +NotUseTimeAgoInWordsCheck: { } +OveruseRouteCustomizationsCheck: { customize_count: 3 } +ProtectMassAssignmentCheck: { } +RemoveEmptyHelpersCheck: { } +#RemoveTabCheck: { } +RemoveTrailingWhitespaceCheck: { } +# RemoveUnusedMethodsInControllersCheck: { except_methods: [] } +RemoveUnusedMethodsInHelpersCheck: { except_methods: [] } +RemoveUnusedMethodsInModelsCheck: { except_methods: [] } +ReplaceComplexCreationWithFactoryMethodCheck: { attribute_assignment_count: 2 } +ReplaceInstanceVariableWithLocalVariableCheck: { } +RestrictAutoGeneratedRoutesCheck: { } +SimplifyRenderInControllersCheck: { } +SimplifyRenderInViewsCheck: { } +#UseBeforeFilterCheck: { customize_count: 2 } +UseModelAssociationCheck: { } +UseMultipartAlternativeAsContentTypeOfEmailCheck: { } +#UseParenthesesInMethodDefCheck: { } +UseObserverCheck: { } +UseQueryAttributeCheck: { } +UseSayWithTimeInMigrationsCheck: { } +UseScopeAccessCheck: { } +UseTurboSprocketsRails3Check: { } From 73309a1888219cee51e11df5bcbfe3383cd366b6 Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Tue, 10 Sep 2013 19:20:07 +0400 Subject: [PATCH 10/21] add handcrafted token auth --- app/controllers/application_controller.rb | 14 ++++++++++ app/models/user.rb | 20 +++++++++++--- config/initializers/devise.rb | 2 +- spec/models/user_spec.rb | 32 +++++++++++++++++++++++ 4 files changed, 64 insertions(+), 4 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3ede7ab..58fa40c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -8,4 +8,18 @@ class ApplicationController < ActionController::API end respond_to :json + + def authenticate_user! + authenticate_user_from_token! + super + end + + def authenticate_user_from_token! + user_token = params[:authentication_token].presence + user = user_token && User.where(authentication_token: user_token).first + + if user + sign_in user, store: false + end + end end diff --git a/app/models/user.rb b/app/models/user.rb index fae21e2..ecb3228 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,9 +1,23 @@ class User < ActiveRecord::Base devise :database_authenticatable, :registerable, - :recoverable, :trackable, :validatable, - :token_authenticatable + :recoverable, :trackable, :validatable - before_save :ensure_authentication_token + before_save :ensure_authentication_token! has_many :comments + + def ensure_authentication_token! + if authentication_token.blank? + self.authentication_token = generate_authentication_token + end + end + + private + + def generate_authentication_token + loop do + token = Devise.friendly_token + break token unless User.where(authentication_token: token).first + end + end end diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 24c4ed7..a95f1a0 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -70,7 +70,7 @@ # Notice that if you are skipping storage for all authentication paths, you # may want to disable generating routes to Devise's sessions controller by # passing :skip => :sessions to `devise_for` in your config/routes.rb - config.skip_session_storage = [:http_auth, :token_auth] + config.skip_session_storage = [:http_auth] # ==> Configuration for :database_authenticatable # For bcrypt, this is the cost for hashing the password and defaults to 10. If diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index b670631..b01af5a 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -11,4 +11,36 @@ describe 'associations' do it { should have_many :comments } end + + describe 'callbacks' do + describe 'before save' do + it 'calls #ensure_authentication_token!' do + u = FactoryGirl.build(:user) + u.should_receive(:ensure_authentication_token!) + + u.save + end + end + end + + describe '#ensure_authentication_token!' do + context 'when token exists' do + it 'leaves it as is' do + user = described_class.new(authentication_token: 'foo') + expect { + user.ensure_authentication_token! + }.not_to change(user, 'authentication_token') + end + end + + context 'when token does NOT exist' do + it 'generates new authentication_token' do + user = described_class.new(authentication_token: '') + + expect { + user.ensure_authentication_token! + }.to change(user, 'authentication_token') + end + end + end end From e7e266c354c95f966e5e18d74aba9433c93a1cac Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Tue, 10 Sep 2013 19:33:06 +0400 Subject: [PATCH 11/21] prepare (not migrate) database on ci --- script/bootstrap | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/script/bootstrap b/script/bootstrap index 61d68a1..bd2ca91 100755 --- a/script/bootstrap +++ b/script/bootstrap @@ -73,6 +73,7 @@ def migrate_db end def prepare_test_db + system('bundle exec rake db:setup') system('bundle exec rake db:test:prepare') end @@ -82,7 +83,7 @@ setup_database_yml setup_dotenv install_bundler install_gems(is_ci ? 'development' : '') -migrate_db -prepare_test_db if is_ci + +is_ci ? prepare_test_db : migrate_db puts 'Everything is up to date.' From 3433b214735c2070979651a3a61d41ffa39848ac Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Thu, 12 Sep 2013 20:07:01 +0400 Subject: [PATCH 12/21] update api_taster to rails 4 --- Gemfile | 3 ++- Gemfile.lock | 25 +++++++++++++++++++++++ config/environments/production.rb | 2 +- config/initializers/api_taster.rb | 5 ++++- config/routes.rb | 9 +++++--- {app => lib}/api_tasters/posts.rb | 0 {app => lib}/api_tasters/sessions.rb | 0 {app => lib}/api_tasters/user/comments.rb | 0 8 files changed, 38 insertions(+), 6 deletions(-) rename {app => lib}/api_tasters/posts.rb (100%) rename {app => lib}/api_tasters/sessions.rb (100%) rename {app => lib}/api_tasters/user/comments.rb (100%) diff --git a/Gemfile b/Gemfile index b59f714..9e054bf 100644 --- a/Gemfile +++ b/Gemfile @@ -42,7 +42,8 @@ group :test do end group :development, :staging do - # gem 'api_taster', git: 'git@github.com:fredwu/api_taster.git' + gem 'api_taster', github: 'vast/api_taster', branch: 'rails4' + # gem 'api_taster', path: '../api_taster' # for local development end group :development, :test, :staging do diff --git a/Gemfile.lock b/Gemfile.lock index 7caa1b8..728b974 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -4,6 +4,19 @@ GIT specs: seedbank (0.3.0.pre2) +GIT + remote: git://github.com/vast/api_taster.git + revision: a1561f51645abe90d64b867b5b9329cee89f19da + branch: rails4 + specs: + api_taster (0.7.0) + bootstrap-sass (~> 2.1) + jquery-rails + rails (~> 4.0.0) + redcarpet + remotipart (~> 1.0) + sass-rails + GEM remote: https://rubygems.org/ specs: @@ -42,6 +55,8 @@ GEM atomic (1.1.13) awesome_print (1.1.0) bcrypt-ruby (3.1.2) + bootstrap-sass (2.3.2.2) + sass (~> 3.2) bourne (1.1.2) mocha (= 0.10.5) brakeman (1.9.3) @@ -120,6 +135,9 @@ GEM highline (1.6.15) hike (1.2.3) i18n (0.6.5) + jquery-rails (3.0.4) + railties (>= 3.0, < 5.0) + thor (>= 0.14, < 2.0) json (1.8.0) launchy (2.2.0) addressable (~> 2.3) @@ -178,6 +196,8 @@ GEM thor (>= 0.18.1, < 2.0) rake (10.1.0) rb-fsevent (0.9.3) + redcarpet (3.0.0) + remotipart (1.2.1) require_all (1.3.0) rspec (2.13.0) rspec-core (~> 2.13.0) @@ -202,6 +222,10 @@ GEM sexp_processor (~> 4.1) rubyzip (0.9.9) sass (3.2.7) + sass-rails (4.0.0) + railties (>= 4.0.0.beta, < 5.0) + sass (>= 3.1.10) + sprockets-rails (~> 2.0.0) selenium-webdriver (2.31.0) childprocess (>= 0.2.5) multi_json (~> 1.0) @@ -260,6 +284,7 @@ PLATFORMS DEPENDENCIES active_model_serializers airbrake + api_taster! brakeman bullet capybara diff --git a/config/environments/production.rb b/config/environments/production.rb index 5236ecc..349ee24 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -9,7 +9,7 @@ config.action_controller.perform_caching = true # Disable Rails's static asset server (Apache or nginx will already do this) - config.serve_static_assets = false + config.serve_static_assets = true # Compress JavaScripts and CSS config.assets.compress = true diff --git a/config/initializers/api_taster.rb b/config/initializers/api_taster.rb index 6002633..333577e 100644 --- a/config/initializers/api_taster.rb +++ b/config/initializers/api_taster.rb @@ -1 +1,4 @@ -ApiTaster.global_params = { format: :json } if defined? ApiTaster +if defined? ApiTaster + ApiTaster.global_params = { format: :json } + ApiTaster.route_path = Rails.root.join('lib', 'api_tasters') +end diff --git a/config/routes.rb b/config/routes.rb index 5918e8b..7bb9dbd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,7 +16,10 @@ # resources :posts, only: [:index, :show] - root :to => 'posts#index' - - mount ApiTaster::Engine => '/api_taster' if defined? ApiTaster::Engine + if defined? ApiTaster::Engine + mount ApiTaster::Engine => '/api_taster' + root to: redirect('/api_taster') + else + root to: 'posts#index' + end end diff --git a/app/api_tasters/posts.rb b/lib/api_tasters/posts.rb similarity index 100% rename from app/api_tasters/posts.rb rename to lib/api_tasters/posts.rb diff --git a/app/api_tasters/sessions.rb b/lib/api_tasters/sessions.rb similarity index 100% rename from app/api_tasters/sessions.rb rename to lib/api_tasters/sessions.rb diff --git a/app/api_tasters/user/comments.rb b/lib/api_tasters/user/comments.rb similarity index 100% rename from app/api_tasters/user/comments.rb rename to lib/api_tasters/user/comments.rb From 22302b585e86ed094081ab709f4d0de580055fa6 Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Fri, 13 Sep 2013 12:56:44 +0400 Subject: [PATCH 13/21] fix simplecov configuration in favor of .simplecov --- .simplecov | 5 +++++ lib/extensions/simplecov/rails_api_profile.rb | 8 -------- spec/spec_helper.rb | 11 +++++------ 3 files changed, 10 insertions(+), 14 deletions(-) create mode 100644 .simplecov delete mode 100644 lib/extensions/simplecov/rails_api_profile.rb diff --git a/.simplecov b/.simplecov new file mode 100644 index 0000000..4d598c1 --- /dev/null +++ b/.simplecov @@ -0,0 +1,5 @@ +SimpleCov.start 'rails' do + add_filter 'api_taster' + add_filter 'examples' + add_filter 'serializers' +end diff --git a/lib/extensions/simplecov/rails_api_profile.rb b/lib/extensions/simplecov/rails_api_profile.rb deleted file mode 100644 index fad117d..0000000 --- a/lib/extensions/simplecov/rails_api_profile.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'simplecov' - -SimpleCov.adapters.define 'rails-api' do - load_adapter 'rails' - add_filter 'api_taster' - add_filter 'examples' - add_filter 'serializers/' -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8eef23b..ee12d12 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,11 +1,10 @@ -require 'extensions/simplecov/rails_api_profile' -SimpleCov.start 'rails-api' +require 'simplecov' -ENV["RAILS_ENV"] ||= 'test' +ENV['RAILS_ENV'] ||= 'test' -require File.expand_path("../../config/environment", __FILE__) +require File.expand_path('../../config/environment', __FILE__) require 'rspec/rails' -# require 'rspec/autorun' should be diabled with guard +# require 'rspec/autorun' should be disabled with guard paths = Dir[Rails.root.join('spec/**/{support,extensions}/**/*.rb')] paths.each { |file| require file } @@ -21,7 +20,7 @@ config.infer_base_class_for_anonymous_controllers = false - config.order = "random" + config.order = 'random' config.before :suite do DatabaseCleaner.strategy = :transaction From 7dac4cf2ebd04f8e97a0cb7ee4387b2dfd67bb44 Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Fri, 13 Sep 2013 13:12:45 +0400 Subject: [PATCH 14/21] add staging configuration environment --- config/environments/staging.rb | 65 ++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 config/environments/staging.rb diff --git a/config/environments/staging.rb b/config/environments/staging.rb new file mode 100644 index 0000000..349ee24 --- /dev/null +++ b/config/environments/staging.rb @@ -0,0 +1,65 @@ +Rails3BaseApi::Application.configure do + # Settings specified here will take precedence over those in config/application.rb + + # Code is not reloaded between requests + config.cache_classes = true + + # Full error reports are disabled and caching is turned on + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Disable Rails's static asset server (Apache or nginx will already do this) + config.serve_static_assets = true + + # Compress JavaScripts and CSS + config.assets.compress = true + + # Don't fallback to assets pipeline if a precompiled asset is missed + config.assets.compile = false + + # Generate digests for assets URLs + config.assets.digest = true + + # Defaults to nil and saved in location specified by config.assets.prefix + # config.assets.manifest = YOUR_PATH + + # 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 + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # See everything in the log (default is :info) + # config.log_level = :debug + + # Prepend all log lines with the following tags + # config.log_tags = [ :subdomain, :uuid ] + + # Use a different logger for distributed setups + # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + + # 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" + + # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) + # config.assets.precompile += %w( search.js ) + + # Disable delivery errors, bad email addresses will be ignored + # config.action_mailer.raise_delivery_errors = false + + # Enable threaded mode + # config.threadsafe! + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation can not be found) + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners + config.active_support.deprecation = :notify + + config.eager_load = true +end From 16866bf90af4de5d80dfcc7337135f2947002aba Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Fri, 13 Sep 2013 13:22:30 +0400 Subject: [PATCH 15/21] switch to ruby 2.0 --- .ruby-version | 2 +- Gemfile | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.ruby-version b/.ruby-version index 311baaf..cb50681 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -1.9.3-p374 +2.0.0-p247 diff --git a/Gemfile b/Gemfile index 9e054bf..d46d78b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,7 @@ source 'https://rubygems.org' +ruby '2.0.0' + gem 'rails', '4.0.0' gem 'rails-api' From 8cfeb8f5be169a4300e4f44d89fa3cbc8ad571db Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Fri, 13 Sep 2013 13:43:01 +0400 Subject: [PATCH 16/21] add rails_12factor gem --- Gemfile | 1 + Gemfile.lock | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/Gemfile b/Gemfile index d46d78b..733c74d 100644 --- a/Gemfile +++ b/Gemfile @@ -14,6 +14,7 @@ gem 'active_model_serializers' gem 'seedbank', github: 'james2m/seedbank' gem 'dotenv' gem 'devise', '~> 3.1.0' +gem 'rails_12factor', group: [:production, :staging] group :development do gem 'letter_opener' diff --git a/Gemfile.lock b/Gemfile.lock index 728b974..dffba08 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -180,6 +180,9 @@ GEM actionpack (>= 3.2.11) railties (>= 3.2.11) tzinfo (~> 0.3.31) + rails_12factor (0.0.2) + rails_serve_static_assets + rails_stdout_logging rails_best_practices (1.14.3) activesupport awesome_print @@ -189,6 +192,8 @@ GEM i18n require_all ruby-progressbar + rails_serve_static_assets (0.0.1) + rails_stdout_logging (0.0.2) railties (4.0.0) actionpack (= 4.0.0) activesupport (= 4.0.0) @@ -303,6 +308,7 @@ DEPENDENCIES pg rails (= 4.0.0) rails-api + rails_12factor rails_best_practices rb-fsevent rspec-rails From c21dfbc37d9fde30447664c33f4af811d666dee5 Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Fri, 13 Sep 2013 13:51:10 +0400 Subject: [PATCH 17/21] add assets to staging environment --- Gemfile | 6 ++++++ Gemfile.lock | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/Gemfile b/Gemfile index 733c74d..f411101 100644 --- a/Gemfile +++ b/Gemfile @@ -53,3 +53,9 @@ group :development, :test, :staging do gem 'faker' gem 'factory_girl_rails' end + +group :staging do + gem 'sass-rails' + gem 'uglifier' + gem 'coffee-rails' +end diff --git a/Gemfile.lock b/Gemfile.lock index dffba08..779355f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -85,6 +85,13 @@ GEM code_analyzer (0.4.2) sexp_processor coderay (1.0.9) + coffee-rails (4.0.0) + coffee-script (>= 2.2.0) + railties (>= 4.0.0.beta, < 5.0) + coffee-script (2.2.0) + coffee-script-source + execjs + coffee-script-source (1.6.3) colored (1.2) columnize (0.3.6) crack (0.3.2) @@ -110,6 +117,7 @@ GEM mail (~> 2.2) erubis (2.7.0) eventmachine (1.0.3) + execjs (2.0.1) factory_girl (4.2.0) activesupport (>= 3.0.0) factory_girl_rails (4.2.1) @@ -271,6 +279,9 @@ GEM polyglot polyglot (>= 0.3.1) tzinfo (0.3.37) + uglifier (2.2.1) + execjs (>= 0.3.0) + multi_json (~> 1.0, >= 1.0.2) uniform_notifier (1.2.0) warden (1.2.3) rack (>= 1.0) @@ -293,6 +304,7 @@ DEPENDENCIES brakeman bullet capybara + coffee-rails database_cleaner debugger decent_exposure @@ -312,9 +324,11 @@ DEPENDENCIES rails_best_practices rb-fsevent rspec-rails + sass-rails seedbank! shoulda-matchers simplecov thin + uglifier webmock zeus From 9727f8c2f29673ee016f138876f93cc718ca52d8 Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Fri, 13 Sep 2013 14:11:38 +0400 Subject: [PATCH 18/21] fallback to AP on staging --- config/application.rb | 10 +--------- config/environments/development.rb | 4 ++++ config/environments/production.rb | 14 +++++++++----- config/environments/staging.rb | 18 +++++++++++------- .../initializers/filter_parameter_logging.rb | 4 ++++ 5 files changed, 29 insertions(+), 21 deletions(-) create mode 100644 config/initializers/filter_parameter_logging.rb diff --git a/config/application.rb b/config/application.rb index 871a4cd..2276273 100644 --- a/config/application.rb +++ b/config/application.rb @@ -7,9 +7,7 @@ require 'sprockets/railtie' # require "rails/test_unit/railtie" -if defined?(Bundler) - Bundler.require(:default, Rails.env) -end +Bundler.require(:default, Rails.env) module Rails3BaseApi class Application < Rails::Application @@ -38,9 +36,6 @@ class Application < Rails::Application # Configure the default encoding used in templates for Ruby 1.9. config.encoding = 'utf-8' - # Configure sensitive parameters which will be filtered from the log file. - config.filter_parameters += [:password] - # Enable escaping HTML in JSON. config.active_support.escape_html_entities_in_json = true @@ -55,9 +50,6 @@ class Application < Rails::Application # Version of your assets, change this if you want to expire all your assets config.assets.version = '1.0' - # If you are deploying Rails 3.1+ on Heroku, you may want to set: - config.assets.initialize_on_precompile = false - # By default Rails API does not include the session middleware. # Add the middleware back in to application b/c it requred by Devise and Warden config.middleware.use ActionDispatch::Session::CookieStore diff --git a/config/environments/development.rb b/config/environments/development.rb index 1abc73b..5a7db90 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -25,5 +25,9 @@ # Expands the lines which load the assets config.assets.debug = true + # Do not eager load code on boot. config.eager_load = false + + # Raise an error on page load if there are pending migrations + config.active_record.migration_error = :page_load end diff --git a/config/environments/production.rb b/config/environments/production.rb index 349ee24..112dd12 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -11,8 +11,9 @@ # Disable Rails's static asset server (Apache or nginx will already do this) config.serve_static_assets = true - # Compress JavaScripts and CSS - config.assets.compress = true + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass # Don't fallback to assets pipeline if a precompiled asset is missed config.assets.compile = false @@ -20,6 +21,9 @@ # Generate digests for assets URLs config.assets.digest = true + # Version of your assets, change this if you want to expire all your assets. + config.assets.version = '1.0' + # Defaults to nil and saved in location specified by config.assets.prefix # config.assets.manifest = YOUR_PATH @@ -51,9 +55,6 @@ # Disable delivery errors, bad email addresses will be ignored # config.action_mailer.raise_delivery_errors = false - # Enable threaded mode - # config.threadsafe! - # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation can not be found) config.i18n.fallbacks = true @@ -62,4 +63,7 @@ config.active_support.deprecation = :notify config.eager_load = true + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new end diff --git a/config/environments/staging.rb b/config/environments/staging.rb index 349ee24..57df2d1 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -11,15 +11,19 @@ # Disable Rails's static asset server (Apache or nginx will already do this) config.serve_static_assets = true - # Compress JavaScripts and CSS - config.assets.compress = true + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass - # Don't fallback to assets pipeline if a precompiled asset is missed - config.assets.compile = false + # Fallback to assets pipeline if a precompiled asset is missed + config.assets.compile = true # Generate digests for assets URLs config.assets.digest = true + # Version of your assets, change this if you want to expire all your assets. + config.assets.version = '1.0' + # Defaults to nil and saved in location specified by config.assets.prefix # config.assets.manifest = YOUR_PATH @@ -51,9 +55,6 @@ # Disable delivery errors, bad email addresses will be ignored # config.action_mailer.raise_delivery_errors = false - # Enable threaded mode - # config.threadsafe! - # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation can not be found) config.i18n.fallbacks = true @@ -62,4 +63,7 @@ config.active_support.deprecation = :notify config.eager_load = true + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new end diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000..4a994e1 --- /dev/null +++ b/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] From 804abb49285c3ce8343aa2b5da8c7b769ffab74c Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Fri, 13 Sep 2013 18:40:32 +0400 Subject: [PATCH 19/21] update README --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index e123c49..9c07a1a 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Status of the API could be checked at http://localhost:5000/api_taster ## What's included -Application currently based on Rails 3.2 stable branch and Ruby 1.9 +Application currently based on Rails 4 and Ruby 2 ### Application gems: @@ -54,4 +54,3 @@ Application currently based on Rails 3.2 stable branch and Ruby 1.9 * `script/bootstrap` - setup required gems and migrate db if needed * `script/quality` - runs brakeman and rails_best_practices for the app * `script/ci` - should be used in the CI, checkout .travis.yml for example -* `script/ci_deploy` - should be used in [Semaphoreapp CI to deploy code to Heroku](http://tatsoft.ru/ci-semaphoreapp) From e3360a935f20bd6005f580ab9e06e4e204b70ab1 Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Fri, 13 Sep 2013 18:40:39 +0400 Subject: [PATCH 20/21] remove ci_deploy script --- script/ci_deploy | 67 ------------------------------------------------ 1 file changed, 67 deletions(-) delete mode 100755 script/ci_deploy diff --git a/script/ci_deploy b/script/ci_deploy deleted file mode 100755 index eb9aefd..0000000 --- a/script/ci_deploy +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env ruby - -# Deploy app to heroku with semaphoreapp -# http://fs.github.com/dev/ci-semaphoreapp -# -# Usage: -# script/ci_deploy branch heroku-app-name heroku-colloborator-private-key-encoded-with-base64 heroku-colloborator-api-key -# Options: -# * branch - will trigger deploy only for this brunch -# * heroku-app-name - name of your heroku application -# * code will be pushed to git from user with this private key. Key should be encoded with base64: base64 /path/to/private_key -# * heroku-colloborator-api-key - user's API key requred for run heroku run rake db:migrate - -require 'fileutils' -require 'base64' - -BRANCH = ARGV.shift -HEROKU_APP = ARGV.shift -KEY_BASE64 = ARGV.shift -API_KEY = ARGV.shift -CURRENT_BRANCH = ENV['BRANCH_NAME'] - -def prepare_ssh - ssh_dir = File.expand_path('~/.ssh') - - FileUtils.mkdir(ssh_dir) unless File.exists?(ssh_dir) - - File.open("#{ssh_dir}/id_rsa", 'w') do |file| - file.write(Base64.decode64(KEY_BASE64)) - end - - File.open("#{ssh_dir}/config", 'a') do |file| - file << <<-HOST - Host *heroku.com* - StrictHostKeyChecking no - UserKnownHostsFile=/dev/null - HOST - end - - File.chmod(0600, "#{ssh_dir}/id_rsa") -end - -def prepare_git - system('git remote rm heroku 2>/dev/null') - system("git remote add heroku git@heroku.com:#{HEROKU_APP}.git") || exit(1) -end - -def deploy - system("git push --force heroku #{BRANCH}:master") || exit(1) -end - -def run_migrations - system("env HEROKU_API_KEY=#{API_KEY} bundle exec heroku run rake db:migrate") || exit(1) -end - -if CURRENT_BRANCH == BRANCH - puts "Going to deploy #{BRANCH}..." - - prepare_ssh - prepare_git - deploy - run_migrations - - puts "Deployed!" -else - puts "Only #{BRANCH} allowed for depoy." -end \ No newline at end of file From 294ce191fee566747cb77138a4fd4fabf7e696e1 Mon Sep 17 00:00:00 2001 From: Vasily Polovnyov Date: Mon, 16 Sep 2013 14:23:34 +0400 Subject: [PATCH 21/21] address code review --- Gemfile | 5 ++++- script/bootstrap | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index f411101..603b5e0 100644 --- a/Gemfile +++ b/Gemfile @@ -14,7 +14,6 @@ gem 'active_model_serializers' gem 'seedbank', github: 'james2m/seedbank' gem 'dotenv' gem 'devise', '~> 3.1.0' -gem 'rails_12factor', group: [:production, :staging] group :development do gem 'letter_opener' @@ -59,3 +58,7 @@ group :staging do gem 'uglifier' gem 'coffee-rails' end + +group :staging, :production do + gem 'rails_12factor' +end diff --git a/script/bootstrap b/script/bootstrap index bd2ca91..7544e79 100755 --- a/script/bootstrap +++ b/script/bootstrap @@ -45,7 +45,7 @@ def install_bundler end end -def install_gems(without = 'production staging') +def install_gems(without: 'production staging') check(:gemfile) do |old_version| # check both Gemfile and Gemfile.lock as there might be local changes that hasn't been bundled yet version = File.read('Gemfile') + File.read('Gemfile.lock') @@ -82,7 +82,7 @@ is_ci = ARGV.shift == 'ci' setup_database_yml setup_dotenv install_bundler -install_gems(is_ci ? 'development' : '') +install_gems(without: is_ci ? 'development' : '') is_ci ? prepare_test_db : migrate_db