├── .gitignore ├── .rspec ├── .ruby-version ├── .travis.yml ├── Gemfile ├── Gemfile.lock ├── LICENSE.txt ├── README.md ├── Rakefile ├── TODO.md ├── app ├── controllers │ ├── api │ │ └── v1 │ │ │ ├── custom_devise │ │ │ └── registrations_controller.rb │ │ │ └── users_controller.rb │ ├── application_controller.rb │ └── concerns │ │ └── .keep ├── helpers │ └── application_helper.rb ├── mailers │ └── .keep ├── models │ ├── .keep │ ├── ability.rb │ ├── concerns │ │ └── .keep │ └── user.rb ├── serializers │ └── user_serializer.rb └── views │ └── layouts │ └── application.html.erb ├── bin ├── bundle ├── rails └── rake ├── config.ru ├── config ├── application.rb ├── boot.rb ├── cucumber.yml ├── database.travis.yml ├── database.yml ├── environment.rb ├── environments │ ├── development.rb │ ├── production.rb │ └── test.rb ├── initializers │ ├── backtrace_silencers.rb │ ├── custom_auth_failure_app.rb │ ├── devise.rb │ ├── filter_parameter_logging.rb │ ├── inflections.rb │ ├── mime_types.rb │ ├── secret_token.rb │ ├── session_store.rb │ └── wrap_parameters.rb ├── locales │ ├── devise.en.yml │ └── en.yml └── routes.rb ├── db ├── migrate │ └── 20130816123807_add_devise_to_users.rb ├── schema.rb └── seeds.rb ├── features ├── api │ └── v1 │ │ ├── authentication │ │ └── sign_up.feature │ │ └── user │ │ └── list_users.feature ├── step_definitions │ └── user_steps.rb └── support │ ├── disable_minitest.rb │ └── env.rb ├── lib ├── api_constraints.rb ├── assets │ └── .keep └── tasks │ ├── .keep │ └── cucumber.rake ├── log └── .keep ├── public ├── 404.html ├── 422.html ├── 500.html ├── favicon.ico └── robots.txt ├── script └── cucumber ├── spec ├── factories │ └── users.rb ├── models │ └── user_spec.rb └── spec_helper.rb └── vendor └── assets ├── javascripts └── .keep └── stylesheets └── .keep /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile '~/.gitignore_global' 6 | 7 | # Ignore bundler config. 8 | /.bundle 9 | 10 | # Ignore the default SQLite database. 11 | /db/*.sqlite3 12 | /db/*.sqlite3-journal 13 | 14 | # Ignore all logfiles and tempfiles. 15 | /log/*.log 16 | /tmp 17 | /features.html 18 | /libpeerconnection.log 19 | /public/api_doc.html 20 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | --format progress 3 | --format html 4 | --out tmp/rspec.html 5 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | ruby-2.0.0 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | 3 | rvm: 4 | - 1.9.3 5 | - 2.0.0 6 | 7 | bundler_args: "--without development production" 8 | 9 | env: 10 | - DB=sqlite 11 | 12 | script: 13 | - RAILS_ENV=test bundle exec rake db:create 14 | - RAILS_ENV=test bundle exec rake db:migrate:reset --trace 15 | - bundle exec rake 16 | 17 | before_script: 18 | - cp config/database.travis.yml config/database.yml 19 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'rails', '4.0.0' 4 | gem 'rails-api' #Rails on API mode 5 | 6 | gem 'sqlite3', group: [:development, :test]# Use sqlite3 as the database for Active Record 7 | gem 'warden', '1.2.3' 8 | gem 'devise' 9 | gem 'cancan' #For authorization 10 | gem 'active_model_serializers' 11 | 12 | # See https://github.com/sstephenson/execjs#readme for more supported runtimes 13 | gem 'therubyracer', platforms: :ruby 14 | 15 | # Use SCSS for stylesheets 16 | gem 'sass-rails', '~> 4.0.0.rc1' 17 | 18 | # Use Uglifier as compressor for JavaScript assets 19 | gem 'uglifier', '>= 1.3.0' 20 | 21 | group :doc do 22 | # bundle exec rake doc:rails generates the API under doc/api. 23 | gem 'sdoc', require: false 24 | end 25 | 26 | # Use unicorn as the app server 27 | gem 'unicorn' 28 | 29 | # Use Capistrano for deployment 30 | # gem 'capistrano', group: :development 31 | 32 | # Use debugger 33 | gem 'debugger', group: [:development, :test] 34 | 35 | #Testing 36 | gem "rspec-rails", :group => [:development, :test] #Unit test framework 37 | gem "database_cleaner", :group => :test #For cleaning database during unit tests 38 | gem "cucumber-rails", :group => :test, :require => false #Behaviour driven development 39 | gem "factory_girl_rails", :group => [:development, :test] #Factory for DB data 40 | gem "shoulda-matchers", :group => :test #Collection of Rails testing matchers 41 | gem 'cucumber-api-steps', :require => false, :group => :test #Cucumber steps for API 42 | gem 'json_spec', group: :test # JSON matchers for tests 43 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actionmailer (4.0.0) 5 | actionpack (= 4.0.0) 6 | mail (~> 2.5.3) 7 | actionpack (4.0.0) 8 | activesupport (= 4.0.0) 9 | builder (~> 3.1.0) 10 | erubis (~> 2.7.0) 11 | rack (~> 1.5.2) 12 | rack-test (~> 0.6.2) 13 | active_model_serializers (0.8.1) 14 | activemodel (>= 3.0) 15 | activemodel (4.0.0) 16 | activesupport (= 4.0.0) 17 | builder (~> 3.1.0) 18 | activerecord (4.0.0) 19 | activemodel (= 4.0.0) 20 | activerecord-deprecated_finders (~> 1.0.2) 21 | activesupport (= 4.0.0) 22 | arel (~> 4.0.0) 23 | activerecord-deprecated_finders (1.0.3) 24 | activesupport (4.0.0) 25 | i18n (~> 0.6, >= 0.6.4) 26 | minitest (~> 4.2) 27 | multi_json (~> 1.3) 28 | thread_safe (~> 0.1) 29 | tzinfo (~> 0.3.37) 30 | arel (4.0.0) 31 | atomic (1.1.13) 32 | bcrypt-ruby (3.1.1) 33 | builder (3.1.4) 34 | cancan (1.6.10) 35 | capybara (2.1.0) 36 | mime-types (>= 1.16) 37 | nokogiri (>= 1.3.3) 38 | rack (>= 1.0.0) 39 | rack-test (>= 0.5.4) 40 | xpath (~> 2.0) 41 | columnize (0.3.6) 42 | cucumber (1.3.6) 43 | builder (>= 2.1.2) 44 | diff-lcs (>= 1.1.3) 45 | gherkin (~> 2.12.0) 46 | multi_json (~> 1.7.5) 47 | multi_test (>= 0.0.2) 48 | cucumber-api-steps (0.10) 49 | cucumber (>= 0.8.3) 50 | jsonpath (>= 0.1.2) 51 | cucumber-rails (1.3.0) 52 | capybara (>= 1.1.2) 53 | cucumber (>= 1.1.8) 54 | nokogiri (>= 1.5.0) 55 | database_cleaner (1.1.1) 56 | debugger (1.6.1) 57 | columnize (>= 0.3.1) 58 | debugger-linecache (~> 1.2.0) 59 | debugger-ruby_core_source (~> 1.2.3) 60 | debugger-linecache (1.2.0) 61 | debugger-ruby_core_source (1.2.3) 62 | devise (3.0.2) 63 | bcrypt-ruby (~> 3.0) 64 | orm_adapter (~> 0.1) 65 | railties (>= 3.2.6, < 5) 66 | warden (~> 1.2.3) 67 | diff-lcs (1.2.4) 68 | erubis (2.7.0) 69 | execjs (1.4.0) 70 | multi_json (~> 1.0) 71 | factory_girl (4.2.0) 72 | activesupport (>= 3.0.0) 73 | factory_girl_rails (4.2.1) 74 | factory_girl (~> 4.2.0) 75 | railties (>= 3.0.0) 76 | gherkin (2.12.1) 77 | multi_json (~> 1.3) 78 | hike (1.2.3) 79 | i18n (0.6.5) 80 | json (1.8.0) 81 | json_spec (1.1.1) 82 | multi_json (~> 1.0) 83 | rspec (~> 2.0) 84 | jsonpath (0.5.3) 85 | multi_json 86 | kgio (2.8.0) 87 | libv8 (3.11.8.17) 88 | mail (2.5.4) 89 | mime-types (~> 1.16) 90 | treetop (~> 1.4.8) 91 | mime-types (1.24) 92 | mini_portile (0.5.1) 93 | minitest (4.7.5) 94 | multi_json (1.7.9) 95 | multi_test (0.0.2) 96 | nokogiri (1.6.0) 97 | mini_portile (~> 0.5.0) 98 | orm_adapter (0.4.0) 99 | polyglot (0.3.3) 100 | rack (1.5.2) 101 | rack-test (0.6.2) 102 | rack (>= 1.0) 103 | rails (4.0.0) 104 | actionmailer (= 4.0.0) 105 | actionpack (= 4.0.0) 106 | activerecord (= 4.0.0) 107 | activesupport (= 4.0.0) 108 | bundler (>= 1.3.0, < 2.0) 109 | railties (= 4.0.0) 110 | sprockets-rails (~> 2.0.0) 111 | rails-api (0.1.0) 112 | actionpack (>= 3.2.11) 113 | railties (>= 3.2.11) 114 | tzinfo (~> 0.3.31) 115 | railties (4.0.0) 116 | actionpack (= 4.0.0) 117 | activesupport (= 4.0.0) 118 | rake (>= 0.8.7) 119 | thor (>= 0.18.1, < 2.0) 120 | raindrops (0.11.0) 121 | rake (10.1.0) 122 | rdoc (3.12.2) 123 | json (~> 1.4) 124 | ref (1.0.5) 125 | rspec (2.14.1) 126 | rspec-core (~> 2.14.0) 127 | rspec-expectations (~> 2.14.0) 128 | rspec-mocks (~> 2.14.0) 129 | rspec-core (2.14.5) 130 | rspec-expectations (2.14.2) 131 | diff-lcs (>= 1.1.3, < 2.0) 132 | rspec-mocks (2.14.3) 133 | rspec-rails (2.14.0) 134 | actionpack (>= 3.0) 135 | activesupport (>= 3.0) 136 | railties (>= 3.0) 137 | rspec-core (~> 2.14.0) 138 | rspec-expectations (~> 2.14.0) 139 | rspec-mocks (~> 2.14.0) 140 | sass (3.2.10) 141 | sass-rails (4.0.0) 142 | railties (>= 4.0.0.beta, < 5.0) 143 | sass (>= 3.1.10) 144 | sprockets-rails (~> 2.0.0) 145 | sdoc (0.3.20) 146 | json (>= 1.1.3) 147 | rdoc (~> 3.10) 148 | shoulda-matchers (2.2.0) 149 | activesupport (>= 3.0.0) 150 | sprockets (2.10.0) 151 | hike (~> 1.2) 152 | multi_json (~> 1.0) 153 | rack (~> 1.0) 154 | tilt (~> 1.1, != 1.3.0) 155 | sprockets-rails (2.0.0) 156 | actionpack (>= 3.0) 157 | activesupport (>= 3.0) 158 | sprockets (~> 2.8) 159 | sqlite3 (1.3.7) 160 | therubyracer (0.11.4) 161 | libv8 (~> 3.11.8.12) 162 | ref 163 | thor (0.18.1) 164 | thread_safe (0.1.2) 165 | atomic 166 | tilt (1.4.1) 167 | treetop (1.4.14) 168 | polyglot 169 | polyglot (>= 0.3.1) 170 | tzinfo (0.3.37) 171 | uglifier (2.1.2) 172 | execjs (>= 0.3.0) 173 | multi_json (~> 1.0, >= 1.0.2) 174 | unicorn (4.6.3) 175 | kgio (~> 2.6) 176 | rack 177 | raindrops (~> 0.7) 178 | warden (1.2.3) 179 | rack (>= 1.0) 180 | xpath (2.0.0) 181 | nokogiri (~> 1.3) 182 | 183 | PLATFORMS 184 | ruby 185 | 186 | DEPENDENCIES 187 | active_model_serializers 188 | cancan 189 | cucumber-api-steps 190 | cucumber-rails 191 | database_cleaner 192 | debugger 193 | devise 194 | factory_girl_rails 195 | json_spec 196 | rails (= 4.0.0) 197 | rails-api 198 | rspec-rails 199 | sass-rails (~> 4.0.0.rc1) 200 | sdoc 201 | shoulda-matchers 202 | sqlite3 203 | therubyracer 204 | uglifier (>= 1.3.0) 205 | unicorn 206 | warden (= 1.2.3) 207 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Emil S 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Rails 4 API 2 | =========== 3 | 4 | [![Build Status](https://travis-ci.org/emilsoman/rails-4-api.png)](https://travis-ci.org/emilsoman/rails-4-api) 5 | 6 | After I published my blog post on [Building a Tested, Documented and Versioned JSON API Using Rails 4](http://www.emilsoman.com/blog/2013/05/18/building-a-tested/), 7 | many readers asked me for a sample template app. So here it is. Feel free to send in pull requests. 8 | 9 | This is a template Rails 4 app which has the following to start with : 10 | 11 | 1. Rails-API - Rails for API only apps 12 | 2. Devise for token based authentication 13 | 3. Cucumber for integration testing + up-to-date API documentation 14 | 4. Versioning using the "Accept" header 15 | 5. Does not depend on cookies/session.( In simple words, the API client need not be a browser ) 16 | 17 | ## Getting started 18 | 19 | cd rails-4-api 20 | bundle install --without production 21 | RAILS_ENV=test bundle exec rake db:setup #Setup the test DB 22 | bundle exec rake #Build ( RSpec + Cucumber ) 23 | #open public/api_doc.html in your browser 24 | 25 | ## Why use Cucumber ? 26 | 27 | I get this question a lot : "Why use Cucumber for API testing ? Why not RSpec controller/request specs ?" 28 | 29 | 1. Cucumber is good at one thing : integration testing using user interaction expressed as steps. API testing = 30 | integration testing , where the user = any API client that can interact with the API in the language of HTTP requests. Use Rack::Test for 31 | HTTP request/response instead of Capybara for page interaction, now you can write API client interaction as steps 32 | and write readable and expressive integration tests. 33 | 2. I want to use the output of the test suite as documentation for my APIs. Cucumber output is perfect for this, because 34 | cucumber forces you to write sequences of steps in a natural language. You would need a hell lot of ruby blocks in RSpec 35 | to produce an output that can act as a self explanatory documentation. 36 | 3. Personal choice. I use RSpec heavily for unit test and I find RSpec is a good fit for that. But writing integration 37 | tests in RSpec doesn't look good to me. But to each his own, there's nothing stopping you from using RSpec for the job. 38 | Read this excellent blog post to see [how you can use RSpec to test APIs](http://matthewlehner.net/rails-api-testing-guidelines/) 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 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 | Rails4Api::Application.load_tasks 7 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | * Branch without devise 2 | -------------------------------------------------------------------------------- /app/controllers/api/v1/custom_devise/registrations_controller.rb: -------------------------------------------------------------------------------- 1 | module Api 2 | module V1 3 | module CustomDevise 4 | class RegistrationsController < Devise::RegistrationsController 5 | prepend_before_filter :require_no_authentication, :only => [ :create ] 6 | 7 | respond_to :json 8 | 9 | # POST /resource 10 | def create 11 | build_resource(sign_up_params) 12 | 13 | resource.role = 'user' 14 | resource.reset_authentication_token 15 | 16 | if resource.save 17 | if resource.active_for_authentication? 18 | sign_up(resource_name, resource) 19 | render json: { 20 | auth_token: resource.authentication_token, 21 | first_name: resource.first_name, 22 | last_name: resource.last_name, 23 | user_role: resource.role 24 | }, status: :created 25 | else 26 | render json: {errors: [resource.inactive_message]}, status: :created 27 | end 28 | else 29 | clean_up_passwords resource 30 | render json: {errors: resource.errors.full_messages}, status: :unprocessable_entity 31 | end 32 | end 33 | 34 | private 35 | 36 | def sign_up_params 37 | params.fetch(:user).permit([:password, :password_confirmation, :email, :first_name, :last_name]) 38 | end 39 | 40 | end 41 | end 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /app/controllers/api/v1/users_controller.rb: -------------------------------------------------------------------------------- 1 | class Api::V1::UsersController < ApplicationController 2 | before_filter :authenticate_user! 3 | 4 | respond_to :json 5 | 6 | # GET /outlet_types 7 | def index 8 | authorize! :read, User 9 | users = current_user.admin? ? User.all : [current_user] 10 | render json: users, status: :ok 11 | end 12 | 13 | end 14 | -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::API 2 | include ActionController::MimeResponds 3 | include ActionController::StrongParameters 4 | include CanCan::ControllerAdditions 5 | 6 | #Handle authorization exception from CanCan 7 | rescue_from CanCan::AccessDenied do |exception| 8 | render json: {errors: ["Insufficient privileges"]}, status: :forbidden 9 | end 10 | 11 | #Handle RecordNotFound errors 12 | rescue_from ActiveRecord::RecordNotFound do |exception| 13 | render json: {errors: [exception.message]}, status: :unprocessable_entity 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emilsoman/rails-4-api/ccda64743dc7bf46cf95c379e4be3dc809048935/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /app/mailers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emilsoman/rails-4-api/ccda64743dc7bf46cf95c379e4be3dc809048935/app/mailers/.keep -------------------------------------------------------------------------------- /app/models/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emilsoman/rails-4-api/ccda64743dc7bf46cf95c379e4be3dc809048935/app/models/.keep -------------------------------------------------------------------------------- /app/models/ability.rb: -------------------------------------------------------------------------------- 1 | class Ability 2 | include CanCan::Ability 3 | 4 | def initialize(user) 5 | # Define abilities for the passed in user here. For example: 6 | # 7 | # user ||= User.new # guest user (not logged in) 8 | # if user.admin? 9 | # can :manage, :all 10 | # else 11 | # can :read, :all 12 | # end 13 | # 14 | # The first argument to `can` is the action you are giving the user 15 | # permission to do. 16 | # If you pass :manage it will apply to every action. Other common actions 17 | # here are :read, :create, :update and :destroy. 18 | # 19 | # The second argument is the resource the user can perform the action on. 20 | # If you pass :all it will apply to every resource. Otherwise pass a Ruby 21 | # class of the resource. 22 | # 23 | # The third argument is an optional hash of conditions to further filter the 24 | # objects. 25 | # For example, here the user can only update published articles. 26 | # 27 | # can :update, Article, :published => true 28 | # 29 | # See the wiki for details: 30 | # https://github.com/ryanb/cancan/wiki/Defining-Abilities 31 | case user.role 32 | when 'admin' 33 | can :read, User 34 | when 'user' 35 | # User's permissions 36 | else 37 | #Default permissions 38 | end 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emilsoman/rails-4-api/ccda64743dc7bf46cf95c379e4be3dc809048935/app/models/concerns/.keep -------------------------------------------------------------------------------- /app/models/user.rb: -------------------------------------------------------------------------------- 1 | class User < ActiveRecord::Base 2 | 3 | devise :database_authenticatable, :registerable, :token_authenticatable, :validatable 4 | 5 | def admin? 6 | role == 'admin' 7 | end 8 | 9 | end 10 | -------------------------------------------------------------------------------- /app/serializers/user_serializer.rb: -------------------------------------------------------------------------------- 1 | class UserSerializer < ActiveModel::Serializer 2 | attributes :id, :first_name, :last_name, :email 3 | end 4 | -------------------------------------------------------------------------------- /app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Rails4Api 5 | <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> 6 | <%= javascript_include_tag "application", "data-turbolinks-track" => true %> 7 | <%= csrf_meta_tags %> 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 3 | load Gem.bin_path('bundler', 'bundle') 4 | -------------------------------------------------------------------------------- /bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path('../../config/application', __FILE__) 3 | require_relative '../config/boot' 4 | require 'rails/commands' 5 | -------------------------------------------------------------------------------- /bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative '../config/boot' 3 | require 'rake' 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run Rails.application 5 | -------------------------------------------------------------------------------- /config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | require 'rails/all' 4 | 5 | # Require the gems listed in Gemfile, including any gems 6 | # you've limited to :test, :development, or :production. 7 | Bundler.require(:default, Rails.env) 8 | 9 | module Rails4Api 10 | class Application < Rails::Application 11 | # Settings in config/environments/* take precedence over those specified here. 12 | # Application configuration should go into files in config/initializers 13 | # -- all .rb files in that directory are automatically loaded. 14 | 15 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 16 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 17 | # config.time_zone = 'Central Time (US & Canada)' 18 | 19 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 20 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 21 | # config.i18n.default_locale = :de 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /config/boot.rb: -------------------------------------------------------------------------------- 1 | # Set up gems listed in the Gemfile. 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 3 | 4 | require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) 5 | -------------------------------------------------------------------------------- /config/cucumber.yml: -------------------------------------------------------------------------------- 1 | <% 2 | rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : "" 3 | rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}" 4 | std_opts = "-r features/support/ -r features/step_definitions --format pretty --format html -o public/api_doc.html --tags ~@wip" 5 | %> 6 | default: <%= std_opts %> features 7 | wip: --tags @wip:3 --wip features 8 | rerun: <%= rerun_opts %> --format rerun --out rerun.txt --tags ~@wip 9 | -------------------------------------------------------------------------------- /config/database.travis.yml: -------------------------------------------------------------------------------- 1 | sqlite: &sqlite 2 | adapter: sqlite3 3 | database: db/<%= Rails.env %>.sqlite3 4 | 5 | defaults: &defaults 6 | pool: 5 7 | timeout: 5000 8 | host: localhost 9 | <<: *<%= ENV['DB'] || "postgresql" %> 10 | 11 | development: 12 | <<: *defaults 13 | 14 | test: &test 15 | <<: *defaults 16 | 17 | production: 18 | <<: *defaults 19 | 20 | cucumber: 21 | <<: *test 22 | -------------------------------------------------------------------------------- /config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite version 3.x 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem 'sqlite3' 6 | development: 7 | adapter: sqlite3 8 | database: db/development.sqlite3 9 | pool: 5 10 | timeout: 5000 11 | 12 | # Warning: The database defined as "test" will be erased and 13 | # re-generated from your development database when you run "rake". 14 | # Do not set this db to the same as development or production. 15 | test: &test 16 | adapter: sqlite3 17 | database: db/test.sqlite3 18 | pool: 5 19 | timeout: 5000 20 | 21 | production: 22 | adapter: sqlite3 23 | database: db/production.sqlite3 24 | pool: 5 25 | timeout: 5000 26 | 27 | cucumber: 28 | <<: *test -------------------------------------------------------------------------------- /config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the Rails application. 5 | Rails4Api::Application.initialize! 6 | -------------------------------------------------------------------------------- /config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Rails4Api::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Do not eager load code on boot. 10 | config.eager_load = false 11 | 12 | # Show full error reports and disable caching. 13 | config.consider_all_requests_local = true 14 | config.action_controller.perform_caching = false 15 | 16 | # Don't care if the mailer can't send. 17 | config.action_mailer.raise_delivery_errors = false 18 | 19 | # Print deprecation notices to the Rails logger. 20 | config.active_support.deprecation = :log 21 | 22 | # Raise an error on page load if there are pending migrations 23 | config.active_record.migration_error = :page_load 24 | 25 | # Debug mode disables concatenation and preprocessing of assets. 26 | # This option may cause significant delays in view rendering with a large 27 | # number of complex assets. 28 | config.assets.debug = true 29 | end 30 | -------------------------------------------------------------------------------- /config/environments/production.rb: -------------------------------------------------------------------------------- 1 | Rails4Api::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # Code is not reloaded between requests. 5 | config.cache_classes = true 6 | 7 | # Eager load code on boot. This eager loads most of Rails and 8 | # your application in memory, allowing both thread web servers 9 | # and those relying on copy on write to perform better. 10 | # Rake tasks automatically ignore this option for performance. 11 | config.eager_load = true 12 | 13 | # Full error reports are disabled and caching is turned on. 14 | config.consider_all_requests_local = false 15 | config.action_controller.perform_caching = true 16 | 17 | # Enable Rack::Cache to put a simple HTTP cache in front of your application 18 | # Add `rack-cache` to your Gemfile before enabling this. 19 | # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. 20 | # config.action_dispatch.rack_cache = true 21 | 22 | # Disable Rails's static asset server (Apache or nginx will already do this). 23 | config.serve_static_assets = false 24 | 25 | # Compress JavaScripts and CSS. 26 | config.assets.js_compressor = :uglifier 27 | # config.assets.css_compressor = :sass 28 | 29 | # Do not fallback to assets pipeline if a precompiled asset is missed. 30 | config.assets.compile = false 31 | 32 | # Generate digests for assets URLs. 33 | config.assets.digest = true 34 | 35 | # Version of your assets, change this if you want to expire all your assets. 36 | config.assets.version = '1.0' 37 | 38 | # Specifies the header that your server uses for sending files. 39 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache 40 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx 41 | 42 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 43 | # config.force_ssl = true 44 | 45 | # Set to :debug to see everything in the log. 46 | config.log_level = :info 47 | 48 | # Prepend all log lines with the following tags. 49 | # config.log_tags = [ :subdomain, :uuid ] 50 | 51 | # Use a different logger for distributed setups. 52 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) 53 | 54 | # Use a different cache store in production. 55 | # config.cache_store = :mem_cache_store 56 | 57 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 58 | # config.action_controller.asset_host = "http://assets.example.com" 59 | 60 | # Precompile additional assets. 61 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. 62 | # config.assets.precompile += %w( search.js ) 63 | 64 | # Ignore bad email addresses and do not raise email delivery errors. 65 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 66 | # config.action_mailer.raise_delivery_errors = false 67 | 68 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 69 | # the I18n.default_locale when a translation can not be found). 70 | config.i18n.fallbacks = true 71 | 72 | # Send deprecation notices to registered listeners. 73 | config.active_support.deprecation = :notify 74 | 75 | # Disable automatic flushing of the log to improve performance. 76 | # config.autoflush_log = false 77 | 78 | # Use default logging formatter so that PID and timestamp are not suppressed. 79 | config.log_formatter = ::Logger::Formatter.new 80 | end 81 | -------------------------------------------------------------------------------- /config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Rails4Api::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Do not eager load code on boot. This avoids loading your whole application 11 | # just for the purpose of running a single test. If you are using a tool that 12 | # preloads Rails for running tests, you may have to set it to true. 13 | config.eager_load = false 14 | 15 | # Configure static asset server for tests with Cache-Control for performance. 16 | config.serve_static_assets = true 17 | config.static_cache_control = "public, max-age=3600" 18 | 19 | # Show full error reports and disable caching. 20 | config.consider_all_requests_local = true 21 | config.action_controller.perform_caching = false 22 | 23 | # Raise exceptions instead of rendering exception templates. 24 | config.action_dispatch.show_exceptions = false 25 | 26 | # Disable request forgery protection in test environment. 27 | config.action_controller.allow_forgery_protection = false 28 | 29 | # Tell Action Mailer not to deliver emails to the real world. 30 | # The :test delivery method accumulates sent emails in the 31 | # ActionMailer::Base.deliveries array. 32 | config.action_mailer.delivery_method = :test 33 | 34 | # Print deprecation notices to the stderr. 35 | config.active_support.deprecation = :stderr 36 | end 37 | -------------------------------------------------------------------------------- /config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /config/initializers/custom_auth_failure_app.rb: -------------------------------------------------------------------------------- 1 | class CustomAuthFailure < Devise::FailureApp 2 | def respond 3 | self.status = 401 4 | self.content_type = 'json' 5 | self.response_body = {"errors" => ["Invalid login"]}.to_json 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /config/initializers/devise.rb: -------------------------------------------------------------------------------- 1 | # Use this hook to configure devise mailer, warden hooks and so forth. 2 | # Many of these configuration options can be set straight in your model. 3 | Devise.setup do |config| 4 | # ==> Mailer Configuration 5 | # Configure the e-mail address which will be shown in Devise::Mailer, 6 | # note that it will be overwritten if you use your own mailer class with default "from" parameter. 7 | config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com" 8 | 9 | # Configure the class responsible to send e-mails. 10 | # config.mailer = "Devise::Mailer" 11 | 12 | # ==> ORM configuration 13 | # Load and configure the ORM. Supports :active_record (default) and 14 | # :mongoid (bson_ext recommended) by default. Other ORMs may be 15 | # available as additional gems. 16 | require 'devise/orm/active_record' 17 | 18 | # ==> Configuration for any authentication mechanism 19 | # Configure which keys are used when authenticating a user. The default is 20 | # just :email. You can configure it to use [:username, :subdomain], so for 21 | # authenticating a user, both parameters are required. Remember that those 22 | # parameters are used only when authenticating and not when retrieving from 23 | # session. If you need permissions, you should implement that in a before filter. 24 | # You can also supply a hash where the value is a boolean determining whether 25 | # or not authentication should be aborted when the value is not present. 26 | # config.authentication_keys = [ :email ] 27 | 28 | # Configure parameters from the request object used for authentication. Each entry 29 | # given should be a request method and it will automatically be passed to the 30 | # find_for_authentication method and considered in your model lookup. For instance, 31 | # if you set :request_keys to [:subdomain], :subdomain will be used on authentication. 32 | # The same considerations mentioned for authentication_keys also apply to request_keys. 33 | # config.request_keys = [] 34 | 35 | # Configure which authentication keys should be case-insensitive. 36 | # These keys will be downcased upon creating or modifying a user and when used 37 | # to authenticate or find a user. Default is :email. 38 | config.case_insensitive_keys = [ :email ] 39 | 40 | # Configure which authentication keys should have whitespace stripped. 41 | # These keys will have whitespace before and after removed upon creating or 42 | # modifying a user and when used to authenticate or find a user. Default is :email. 43 | config.strip_whitespace_keys = [ :email ] 44 | 45 | # Tell if authentication through request.params is enabled. True by default. 46 | # It can be set to an array that will enable params authentication only for the 47 | # given strategies, for example, `config.params_authenticatable = [:database]` will 48 | # enable it only for database (email + password) authentication. 49 | # config.params_authenticatable = true 50 | 51 | # Tell if authentication through HTTP Auth is enabled. False by default. 52 | # It can be set to an array that will enable http authentication only for the 53 | # given strategies, for example, `config.http_authenticatable = [:token]` will 54 | # enable it only for token authentication. The supported strategies are: 55 | # :database = Support basic authentication with authentication key + password 56 | # :token = Support basic authentication with token authentication key 57 | # :token_options = Support token authentication with options as defined in 58 | # http://api.rubyonrails.org/classes/ActionController/HttpAuthentication/Token.html 59 | config.http_authenticatable = [:token] 60 | 61 | # If http headers should be returned for AJAX requests. True by default. 62 | # config.http_authenticatable_on_xhr = true 63 | 64 | # The realm used in Http Basic Authentication. "Application" by default. 65 | # config.http_authentication_realm = "Application" 66 | 67 | # It will change confirmation, password recovery and other workflows 68 | # to behave the same regardless if the e-mail provided was right or wrong. 69 | # Does not affect registerable. 70 | # config.paranoid = true 71 | 72 | # By default Devise will store the user in session. You can skip storage for 73 | # :http_auth and :token_auth by adding those symbols to the array below. 74 | # Notice that if you are skipping storage for all authentication paths, you 75 | # may want to disable generating routes to Devise's sessions controller by 76 | # passing :skip => :sessions to `devise_for` in your config/routes.rb 77 | config.skip_session_storage = [:http_auth] 78 | 79 | # By default, Devise cleans up the CSRF token on authentication to 80 | # avoid CSRF token fixation attacks. This means that, when using AJAX 81 | # requests for sign in and sign up, you need to get a new CSRF token 82 | # from the server. You can disable this option at your own risk. 83 | # config.clean_up_csrf_token_on_authentication = true 84 | 85 | # ==> Configuration for :database_authenticatable 86 | # For bcrypt, this is the cost for hashing the password and defaults to 10. If 87 | # using other encryptors, it sets how many times you want the password re-encrypted. 88 | # 89 | # Limiting the stretches to just one in testing will increase the performance of 90 | # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use 91 | # a value less than 10 in other environments. 92 | config.stretches = Rails.env.test? ? 1 : 10 93 | 94 | # Setup a pepper to generate the encrypted password. 95 | # config.pepper = "f280dcca457fac0050a8e379b67283edffff14b6fbe87e31906202a2f04d9dbbcbb1c36f65240e2b349649962bcc79b37bd4c6787fe3da714f4fe028f22f8786" 96 | 97 | # ==> Configuration for :confirmable 98 | # A period that the user is allowed to access the website even without 99 | # confirming his account. For instance, if set to 2.days, the user will be 100 | # able to access the website for two days without confirming his account, 101 | # access will be blocked just in the third day. Default is 0.days, meaning 102 | # the user cannot access the website without confirming his account. 103 | # config.allow_unconfirmed_access_for = 2.days 104 | 105 | # A period that the user is allowed to confirm their account before their 106 | # token becomes invalid. For example, if set to 3.days, the user can confirm 107 | # their account within 3 days after the mail was sent, but on the fourth day 108 | # their account can't be confirmed with the token any more. 109 | # Default is nil, meaning there is no restriction on how long a user can take 110 | # before confirming their account. 111 | # config.confirm_within = 3.days 112 | 113 | # If true, requires any email changes to be confirmed (exactly the same way as 114 | # initial account confirmation) to be applied. Requires additional unconfirmed_email 115 | # db field (see migrations). Until confirmed new email is stored in 116 | # unconfirmed email column, and copied to email column on successful confirmation. 117 | config.reconfirmable = true 118 | 119 | # Defines which key will be used when confirming an account 120 | # config.confirmation_keys = [ :email ] 121 | 122 | # ==> Configuration for :rememberable 123 | # The time the user will be remembered without asking for credentials again. 124 | # config.remember_for = 2.weeks 125 | 126 | # If true, extends the user's remember period when remembered via cookie. 127 | # config.extend_remember_period = false 128 | 129 | # Options to be passed to the created cookie. For instance, you can set 130 | # :secure => true in order to force SSL only cookies. 131 | # config.rememberable_options = {} 132 | 133 | # ==> Configuration for :validatable 134 | # Range for password length. Default is 8..128. 135 | config.password_length = 8..128 136 | 137 | # Email regex used to validate email formats. It simply asserts that 138 | # one (and only one) @ exists in the given string. This is mainly 139 | # to give user feedback and not to assert the e-mail validity. 140 | # config.email_regexp = /\A[^@]+@[^@]+\z/ 141 | 142 | # ==> Configuration for :timeoutable 143 | # The time you want to timeout the user session without activity. After this 144 | # time the user will be asked for credentials again. Default is 30 minutes. 145 | # config.timeout_in = 30.minutes 146 | 147 | # If true, expires auth token on session timeout. 148 | # config.expire_auth_token_on_timeout = false 149 | 150 | # ==> Configuration for :lockable 151 | # Defines which strategy will be used to lock an account. 152 | # :failed_attempts = Locks an account after a number of failed attempts to sign in. 153 | # :none = No lock strategy. You should handle locking by yourself. 154 | # config.lock_strategy = :failed_attempts 155 | 156 | # Defines which key will be used when locking and unlocking an account 157 | # config.unlock_keys = [ :email ] 158 | 159 | # Defines which strategy will be used to unlock an account. 160 | # :email = Sends an unlock link to the user email 161 | # :time = Re-enables login after a certain amount of time (see :unlock_in below) 162 | # :both = Enables both strategies 163 | # :none = No unlock strategy. You should handle unlocking by yourself. 164 | # config.unlock_strategy = :both 165 | 166 | # Number of authentication tries before locking an account if lock_strategy 167 | # is failed attempts. 168 | # config.maximum_attempts = 20 169 | 170 | # Time interval to unlock the account if :time is enabled as unlock_strategy. 171 | # config.unlock_in = 1.hour 172 | 173 | # ==> Configuration for :recoverable 174 | # 175 | # Defines which key will be used when recovering the password for an account 176 | # config.reset_password_keys = [ :email ] 177 | 178 | # Time interval you can reset your password with a reset password key. 179 | # Don't put a too small interval or your users won't have the time to 180 | # change their passwords. 181 | config.reset_password_within = 6.hours 182 | 183 | # ==> Configuration for :encryptable 184 | # Allow you to use another encryption algorithm besides bcrypt (default). You can use 185 | # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1, 186 | # :authlogic_sha512 (then you should set stretches above to 20 for default behavior) 187 | # and :restful_authentication_sha1 (then you should set stretches to 10, and copy 188 | # REST_AUTH_SITE_KEY to pepper). 189 | # 190 | # Require the `devise-encryptable` gem when using anything other than bcrypt 191 | # config.encryptor = :sha512 192 | 193 | # ==> Configuration for :token_authenticatable 194 | # Defines name of the authentication token params key 195 | # config.token_authentication_key = :auth_token 196 | 197 | # ==> Scopes configuration 198 | # Turn scoped views on. Before rendering "sessions/new", it will first check for 199 | # "users/sessions/new". It's turned off by default because it's slower if you 200 | # are using only default views. 201 | # config.scoped_views = false 202 | 203 | # Configure the default scope given to Warden. By default it's the first 204 | # devise role declared in your routes (usually :user). 205 | # config.default_scope = :user 206 | 207 | # Set this configuration to false if you want /users/sign_out to sign out 208 | # only the current scope. By default, Devise signs out all scopes. 209 | # config.sign_out_all_scopes = true 210 | 211 | # ==> Navigation configuration 212 | # Lists the formats that should be treated as navigational. Formats like 213 | # :html, should redirect to the sign in page when the user does not have 214 | # access, but formats like :xml or :json, should return 401. 215 | # 216 | # If you have any extra navigational formats, like :iphone or :mobile, you 217 | # should add them to the navigational formats lists. 218 | # 219 | # The "*/*" below is required to match Internet Explorer requests. 220 | # config.navigational_formats = ["*/*", :html] 221 | 222 | # The default HTTP method used to sign out a resource. Default is :delete. 223 | config.sign_out_via = :delete 224 | 225 | # ==> OmniAuth 226 | # Add a new OmniAuth provider. Check the wiki for more information on setting 227 | # up on your models and hooks. 228 | # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo' 229 | 230 | # ==> Warden configuration 231 | # If you want to use other strategies, that are not supported by Devise, or 232 | # change the failure app, you can configure them inside the config.warden block. 233 | # 234 | # config.warden do |manager| 235 | # manager.intercept_401 = false 236 | # manager.default_strategies(:scope => :user).unshift :some_external_strategy 237 | # end 238 | config.warden do |manager| 239 | manager.failure_app = CustomAuthFailure 240 | end 241 | 242 | # ==> Mountable engine configurations 243 | # When using Devise inside an engine, let's call it `MyEngine`, and this engine 244 | # is mountable, there are some extra configurations to be taken into account. 245 | # The following options are available, assuming the engine is mounted as: 246 | # 247 | # mount MyEngine, at: "/my_engine" 248 | # 249 | # The router that invoked `devise_for`, in the example above, would be: 250 | # config.router_name = :my_engine 251 | # 252 | # When using omniauth, Devise cannot automatically set Omniauth path, 253 | # so you need to do it manually. For the users scope, it would be: 254 | # config.omniauth_path_prefix = "/my_engine/users/auth" 255 | end 256 | -------------------------------------------------------------------------------- /config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure sensitive parameters which will be filtered from the log file. 4 | Rails.application.config.filter_parameters += [:password] 5 | -------------------------------------------------------------------------------- /config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, '\1en' 8 | # inflect.singular /^(ox)en/i, '\1' 9 | # inflect.irregular 'person', 'people' 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym 'RESTful' 16 | # end 17 | -------------------------------------------------------------------------------- /config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | # Mime::Type.register_alias "text/html", :iphone 6 | -------------------------------------------------------------------------------- /config/initializers/secret_token.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key is used for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | 6 | # Make sure the secret is at least 30 characters and all random, 7 | # no regular words or you'll be exposed to dictionary attacks. 8 | # You can use `rake secret` to generate a secure secret key. 9 | 10 | # Make sure your secret_key_base is kept private 11 | # if you're sharing your code publicly. 12 | Rails4Api::Application.config.secret_key_base = 'edf00c6d56b27c5e42c3f259e5cfb1f5fc2a32b36be644483e3d5012a6cea539238848af0ec84656f94dea9a36ae7f410804525ab1bcb414a4341c005f46738e' 13 | -------------------------------------------------------------------------------- /config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Rails4Api::Application.config.session_store :cookie_store, key: '_rails-4-api_session' 4 | -------------------------------------------------------------------------------- /config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] if respond_to?(:wrap_parameters) 9 | end 10 | 11 | # To enable root element in JSON for ActiveRecord objects. 12 | # ActiveSupport.on_load(:active_record) do 13 | # self.include_root_in_json = true 14 | # end 15 | -------------------------------------------------------------------------------- /config/locales/devise.en.yml: -------------------------------------------------------------------------------- 1 | # Additional translations at https://github.com/plataformatec/devise/wiki/I18n 2 | 3 | en: 4 | devise: 5 | confirmations: 6 | confirmed: "Your account was successfully confirmed. You are now signed in." 7 | send_instructions: "You will receive an email with instructions about how to confirm your account in a few minutes." 8 | send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes." 9 | failure: 10 | already_authenticated: "You are already signed in." 11 | inactive: "Your account was not activated yet." 12 | invalid: "Invalid email or password." 13 | invalid_token: "Invalid authentication token." 14 | locked: "Your account is locked." 15 | not_found_in_database: "Invalid email or password." 16 | timeout: "Your session expired, please sign in again to continue." 17 | unauthenticated: "You need to sign in or sign up before continuing." 18 | unconfirmed: "You have to confirm your account before continuing." 19 | mailer: 20 | confirmation_instructions: 21 | subject: "Confirmation instructions" 22 | reset_password_instructions: 23 | subject: "Reset password instructions" 24 | unlock_instructions: 25 | subject: "Unlock Instructions" 26 | omniauth_callbacks: 27 | failure: "Could not authenticate you from %{kind} because \"%{reason}\"." 28 | success: "Successfully authenticated from %{kind} account." 29 | passwords: 30 | no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided." 31 | send_instructions: "You will receive an email with instructions about how to reset your password in a few minutes." 32 | send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes." 33 | updated: "Your password was changed successfully. You are now signed in." 34 | updated_not_active: "Your password was changed successfully." 35 | registrations: 36 | destroyed: "Bye! Your account was successfully cancelled. We hope to see you again soon." 37 | signed_up: "Welcome! You have signed up successfully." 38 | signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated." 39 | signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked." 40 | signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please open the link to activate your account." 41 | update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address." 42 | updated: "You updated your account successfully." 43 | sessions: 44 | signed_in: "Signed in successfully." 45 | signed_out: "Signed out successfully." 46 | unlocks: 47 | send_instructions: "You will receive an email with instructions about how to unlock your account in a few minutes." 48 | send_paranoid_instructions: "If your account exists, you will receive an email with instructions about how to unlock it in a few minutes." 49 | unlocked: "Your account has been unlocked successfully. Please sign in to continue." 50 | errors: 51 | messages: 52 | already_confirmed: "was already confirmed, please try signing in" 53 | confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one" 54 | expired: "has expired, please request a new one" 55 | not_found: "not found" 56 | not_locked: "was not locked" 57 | not_saved: 58 | one: "1 error prohibited this %{resource} from being saved:" 59 | other: "%{count} errors prohibited this %{resource} from being saved:" 60 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t 'hello' 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t('hello') %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # To learn more, please read the Rails Internationalization guide 20 | # available at http://guides.rubyonrails.org/i18n.html. 21 | 22 | en: 23 | hello: "Hello world" 24 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | require 'api_constraints' 2 | 3 | Rails4Api::Application.routes.draw do 4 | 5 | scope module: :v1, constraints: ApiConstraints.new(version: 1, default: :true) do 6 | devise_for :users, path: '/api/users',controllers: { 7 | registrations: 'api/v1/custom_devise/registrations' 8 | } 9 | end 10 | 11 | namespace :api, defaults: {format: 'json'} do 12 | scope module: :v1, constraints: ApiConstraints.new(version: 1, default: :true) do 13 | resources :users, :only => [:index] 14 | end 15 | end 16 | 17 | #root :to => "home#index" 18 | end 19 | -------------------------------------------------------------------------------- /db/migrate/20130816123807_add_devise_to_users.rb: -------------------------------------------------------------------------------- 1 | class AddDeviseToUsers < ActiveRecord::Migration 2 | def self.up 3 | create_table(:users) do |t| 4 | 5 | #Non devise user fields 6 | t.string :first_name 7 | t.string :last_name 8 | t.string :role, :null => false 9 | 10 | ## Database authenticatable 11 | t.string :email, :null => false, :default => "" 12 | t.string :encrypted_password, :null => false, :default => "" 13 | 14 | ## Recoverable 15 | # t.string :reset_password_token 16 | # t.datetime :reset_password_sent_at 17 | 18 | ## Rememberable 19 | # t.datetime :remember_created_at 20 | 21 | ## Trackable 22 | # t.integer :sign_in_count, :default => 0 23 | # t.datetime :current_sign_in_at 24 | # t.datetime :last_sign_in_at 25 | # t.string :current_sign_in_ip 26 | # t.string :last_sign_in_ip 27 | 28 | ## Confirmable 29 | # t.string :confirmation_token 30 | # t.datetime :confirmed_at 31 | # t.datetime :confirmation_sent_at 32 | # t.string :unconfirmed_email # Only if using reconfirmable 33 | 34 | ## Lockable 35 | # t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts 36 | # t.string :unlock_token # Only if unlock strategy is :email or :both 37 | # t.datetime :locked_at 38 | 39 | ## Token authenticatable 40 | t.string :authentication_token 41 | 42 | 43 | # Uncomment below if timestamps were not included in your original model. 44 | # t.timestamps 45 | end 46 | 47 | add_index :users, :email, :unique => true 48 | # add_index :users, :reset_password_token, :unique => true 49 | # add_index :users, :confirmation_token, :unique => true 50 | # add_index :users, :unlock_token, :unique => true 51 | # add_index :users, :authentication_token, :unique => true 52 | end 53 | 54 | def self.down 55 | # By default, we don't want to make any assumption about how to roll back a migration when your 56 | # model already existed. Please edit below which fields you would like to remove in this migration. 57 | raise ActiveRecord::IrreversibleMigration 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /db/schema.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | # This file is auto-generated from the current state of the database. Instead 3 | # of editing this file, please use the migrations feature of Active Record to 4 | # incrementally modify your database, and then regenerate this schema definition. 5 | # 6 | # Note that this schema.rb definition is the authoritative source for your 7 | # database schema. If you need to create the application database on another 8 | # system, you should be using db:schema:load, not running all the migrations 9 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations 10 | # you'll amass, the slower it'll run and the greater likelihood for issues). 11 | # 12 | # It's strongly recommended that you check this file into your version control system. 13 | 14 | ActiveRecord::Schema.define(version: 20130816123807) do 15 | 16 | create_table "users", force: true do |t| 17 | t.string "first_name" 18 | t.string "last_name" 19 | t.string "role", null: false 20 | t.string "email", default: "", null: false 21 | t.string "encrypted_password", default: "", null: false 22 | t.string "authentication_token" 23 | end 24 | 25 | add_index "users", ["email"], name: "index_users_on_email", unique: true 26 | 27 | end 28 | -------------------------------------------------------------------------------- /db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should contain all the record creation needed to seed the database with its default values. 2 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) 7 | # Mayor.create(name: 'Emanuel', city: cities.first) 8 | -------------------------------------------------------------------------------- /features/api/v1/authentication/sign_up.feature: -------------------------------------------------------------------------------- 1 | Feature: Sign Up 2 | 3 | Background: 4 | Given I send and accept JSON 5 | 6 | Scenario: Successful sign up 7 | When I send a POST request to "/api/users" with the following: 8 | """ 9 | { 10 | "user" : { 11 | "first_name": "Saul", 12 | "last_name": "Hudson", 13 | "email": "slash@gmail.com", 14 | "password": "sekr@t123", 15 | "password_confirmation": "sekr@t123" 16 | } 17 | } 18 | """ 19 | Then the response status should be "201" 20 | And the JSON response should have "auth_token" 21 | And the JSON response at "auth_token" should be a string 22 | And the JSON response at "user_role" should be "user" 23 | And the JSON response at "first_name" should be "Saul" 24 | And the JSON response at "last_name" should be "Hudson" 25 | Given I keep the JSON response at "auth_token" as "AUTH_TOKEN" 26 | Then the user with email "slash@gmail.com" should have "%{AUTH_TOKEN}" as his authentication_token 27 | And a user should be present with the following 28 | |first_name|Saul| 29 | |last_name|Hudson| 30 | |email|slash@gmail.com| 31 | 32 | 33 | Scenario: Passwords do not match 34 | When I send a POST request to "/api/users" with the following: 35 | """ 36 | { 37 | "user" : { 38 | "first_name": "Kobe", 39 | "last_name": "Bryant", 40 | "email": "kobe@gmail.com", 41 | "password": "kobe1234", 42 | "password_confirmation": "kobe12345" 43 | } 44 | } 45 | """ 46 | Then the response status should be "422" 47 | And the JSON response should be: 48 | """ 49 | {"errors" : ["Password confirmation doesn't match Password"]} 50 | """ 51 | 52 | Scenario: Email is already taken 53 | Given "Adam" is a user with email id "user@gmail.com" and password "password123" 54 | When I send a POST request to "/api/users" with the following: 55 | """ 56 | { 57 | "user" : { 58 | "first_name": "Kobe", 59 | "last_name": "Bryant", 60 | "email": "user@gmail.com", 61 | "password": "kobe1234", 62 | "password_confirmation": "kobe1234" 63 | } 64 | } 65 | """ 66 | Then the response status should be "422" 67 | And the JSON response should be: 68 | """ 69 | {"errors" : ["Email has already been taken"]} 70 | """ 71 | -------------------------------------------------------------------------------- /features/api/v1/user/list_users.feature: -------------------------------------------------------------------------------- 1 | Feature: List Users 2 | 3 | Background: 4 | Given I send and accept JSON 5 | 6 | Scenario: Successfully list users when logged in user is admin 7 | Given the following users exist 8 | |id|email |first_name |last_name |password |authentication_token|role | 9 | |10|user1@gmail.com |First |User |test1234 |auth_token_123 |user | 10 | |11|user2@gmail.com |Second |User |test1234 |auth_token_223 |user | 11 | |12|user3@gmail.com |Third |User |test1234 |auth_token_323 |user | 12 | |13|user4@gmail.com |Fourth |User |test1234 |auth_token_423 |user | 13 | |14|user5@gmail.com |Fifth |User |test1234 |auth_token_523 |admin| 14 | When I authenticate as the user "auth_token_523" with the password "random string" 15 | And I send a GET request to "/api/users" 16 | And the JSON response should be: 17 | """ 18 | { 19 | "users": [ 20 | { 21 | "email": "user1@gmail.com", 22 | "first_name": "First", 23 | "last_name": "User" 24 | }, 25 | { 26 | "email": "user2@gmail.com", 27 | "first_name": "Second", 28 | "last_name": "User" 29 | }, 30 | { 31 | "email": "user3@gmail.com", 32 | "first_name": "Third", 33 | "last_name": "User" 34 | }, 35 | { 36 | "email": "user4@gmail.com", 37 | "first_name": "Fourth", 38 | "last_name": "User" 39 | }, 40 | { 41 | "email": "user5@gmail.com", 42 | "first_name": "Fifth", 43 | "last_name": "User" 44 | } 45 | ] 46 | } 47 | """ 48 | Then the response status should be "200" 49 | 50 | Scenario: Logged in user is not admin 51 | Given the following users exist 52 | |id|email |first_name |last_name |password |authentication_token|role | 53 | |10|user1@gmail.com |First |User |test1234 |auth_token_123 |user | 54 | |11|user2@gmail.com |Second |User |test1234 |auth_token_223 |user | 55 | |12|user3@gmail.com |Third |User |test1234 |auth_token_323 |user | 56 | |13|user4@gmail.com |Fourth |User |test1234 |auth_token_423 |user | 57 | |14|user5@gmail.com |Fifth |User |test1234 |auth_token_523 |admin| 58 | When I authenticate as the user "auth_token_123" with the password "random string" 59 | And I send a GET request to "/api/users" 60 | Then the response status should be "403" 61 | And the JSON response should be: 62 | """ 63 | {"errors" : ["Insufficient privileges"]} 64 | """ 65 | 66 | Scenario: User is not authenticated 67 | When I authenticate as the user "invalid_auth_token" with the password "random string" 68 | And I send a GET request to "/api/users" 69 | Then the response status should be "401" 70 | And the JSON response should be: 71 | """ 72 | { "errors": ["Invalid login"] } 73 | """ 74 | -------------------------------------------------------------------------------- /features/step_definitions/user_steps.rb: -------------------------------------------------------------------------------- 1 | Given /^"([^"]*)" is a user with email id "([^"]*)" and password "([^"]*)"$/ do |full_name, email, password| 2 | first_name, last_name = full_name.split 3 | @user = User.create(email: email, password: password, password_confirmation: password, first_name: first_name.to_s, last_name: last_name.to_s, role: 'user') 4 | end 5 | 6 | And /^his authentication token is "([^"]*)"$/ do |auth_token| 7 | @user.authentication_token = auth_token 8 | @user.save! 9 | end 10 | 11 | And /^his role is "([^"]*)"$/ do |role| 12 | @user.role = role 13 | @user.save! 14 | end 15 | 16 | 17 | And /^the auth_token should be different from "([^"]*)"$/ do |auth_token| 18 | @user.reload 19 | @user.authentication_token.should_not == auth_token 20 | end 21 | 22 | And /^the auth_token should still be "([^"]*)"$/ do |auth_token| 23 | @user.reload 24 | @user.authentication_token.should == auth_token 25 | end 26 | 27 | Then /^the user with email "([^"]*)" should have "([^"]*)" as his authentication_token$/ do |email, token| 28 | JsonSpec.remember(token).should == User.where(email: email).first.authentication_token.to_json 29 | end 30 | 31 | And /^his password should be "([^"]*)"$/ do |password| 32 | @user.reload 33 | @user.valid_password?(password).should be_true 34 | end 35 | 36 | Then(/^a user should be present with the following$/) do |table| 37 | User.where(table.rows_hash).present?.should be_true 38 | end 39 | 40 | Given "the following user exists" do |table| 41 | User.create!(table.rows_hash) 42 | end 43 | 44 | Then(/^there should not be any user with email "(.*?)"$/) do |email| 45 | User.where(email: email).first.should be_nil 46 | end 47 | 48 | Given "the following users exist" do |user_data| 49 | user_hashes = user_data.hashes 50 | user_hashes.each do |user_hash| 51 | user_hash["password_confirmation"] = user_hash["password"] 52 | User.create!(user_hash) 53 | end 54 | User.count.should == user_hashes.size 55 | end 56 | -------------------------------------------------------------------------------- /features/support/disable_minitest.rb: -------------------------------------------------------------------------------- 1 | require 'multi_test' 2 | MultiTest.disable_autorun 3 | -------------------------------------------------------------------------------- /features/support/env.rb: -------------------------------------------------------------------------------- 1 | # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. 2 | # It is recommended to regenerate this file in the future when you upgrade to a 3 | # newer version of cucumber-rails. Consider adding your own code to a new file 4 | # instead of editing this one. Cucumber will automatically load all features/**/*.rb 5 | # files. 6 | 7 | require 'cucumber/rails' 8 | require 'cucumber/api_steps' 9 | require "json_spec/cucumber" 10 | 11 | #For json_spec 12 | def last_json 13 | page.source 14 | end 15 | 16 | And "debugger" do 17 | require 'debugger'; debugger 18 | end 19 | 20 | # Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In 21 | # order to ease the transition to Capybara we set the default here. If you'd 22 | # prefer to use XPath just remove this line and adjust any selectors in your 23 | # steps to use the XPath syntax. 24 | Capybara.default_selector = :css 25 | 26 | # By default, any exception happening in your Rails application will bubble up 27 | # to Cucumber so that your scenario will fail. This is a different from how 28 | # your application behaves in the production environment, where an error page will 29 | # be rendered instead. 30 | # 31 | # Sometimes we want to override this default behaviour and allow Rails to rescue 32 | # exceptions and display an error page (just like when the app is running in production). 33 | # Typical scenarios where you want to do this is when you test your error pages. 34 | # There are two ways to allow Rails to rescue exceptions: 35 | # 36 | # 1) Tag your scenario (or feature) with @allow-rescue 37 | # 38 | # 2) Set the value below to true. Beware that doing this globally is not 39 | # recommended as it will mask a lot of errors for you! 40 | # 41 | ActionController::Base.allow_rescue = false 42 | 43 | # Remove/comment out the lines below if your app doesn't have a database. 44 | # For some databases (like MongoDB and CouchDB) you may need to use :truncation instead. 45 | begin 46 | DatabaseCleaner.strategy = :transaction 47 | rescue NameError 48 | raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it." 49 | end 50 | 51 | Before do 52 | DatabaseCleaner.start 53 | end 54 | 55 | After do |scenario| 56 | DatabaseCleaner.clean 57 | end 58 | 59 | # You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios. 60 | # See the DatabaseCleaner documentation for details. Example: 61 | # 62 | # Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do 63 | # # { :except => [:widgets] } may not do what you expect here 64 | # # as tCucumber::Rails::Database.javascript_strategy overrides 65 | # # this setting. 66 | # DatabaseCleaner.strategy = :truncation 67 | # end 68 | # 69 | # Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do 70 | # DatabaseCleaner.strategy = :transaction 71 | # end 72 | # 73 | 74 | # Possible values are :truncation and :transaction 75 | # The :transaction strategy is faster, but might give you threading problems. 76 | # See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature 77 | Cucumber::Rails::Database.javascript_strategy = :truncation 78 | 79 | -------------------------------------------------------------------------------- /lib/api_constraints.rb: -------------------------------------------------------------------------------- 1 | class ApiConstraints 2 | def initialize(options) 3 | @version = options[:version] 4 | @default = options[:default] 5 | end 6 | 7 | def matches?(req) 8 | @default || req.headers['Accept'].include?("application/vnd.kanari.v#{@version}") 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/assets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emilsoman/rails-4-api/ccda64743dc7bf46cf95c379e4be3dc809048935/lib/assets/.keep -------------------------------------------------------------------------------- /lib/tasks/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emilsoman/rails-4-api/ccda64743dc7bf46cf95c379e4be3dc809048935/lib/tasks/.keep -------------------------------------------------------------------------------- /lib/tasks/cucumber.rake: -------------------------------------------------------------------------------- 1 | # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. 2 | # It is recommended to regenerate this file in the future when you upgrade to a 3 | # newer version of cucumber-rails. Consider adding your own code to a new file 4 | # instead of editing this one. Cucumber will automatically load all features/**/*.rb 5 | # files. 6 | 7 | 8 | unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks 9 | 10 | vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first 11 | $LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil? 12 | 13 | begin 14 | require 'cucumber/rake/task' 15 | 16 | namespace :cucumber do 17 | Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t| 18 | t.binary = vendored_cucumber_bin # If nil, the gem's binary is used. 19 | t.fork = true # You may get faster startup if you set this to false 20 | t.profile = 'default' 21 | end 22 | 23 | Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t| 24 | t.binary = vendored_cucumber_bin 25 | t.fork = true # You may get faster startup if you set this to false 26 | t.profile = 'wip' 27 | end 28 | 29 | Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t| 30 | t.binary = vendored_cucumber_bin 31 | t.fork = true # You may get faster startup if you set this to false 32 | t.profile = 'rerun' 33 | end 34 | 35 | desc 'Run all features' 36 | task :all => [:ok, :wip] 37 | 38 | task :statsetup do 39 | require 'rails/code_statistics' 40 | ::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features') 41 | ::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features') 42 | end 43 | end 44 | desc 'Alias for cucumber:ok' 45 | task :cucumber => 'cucumber:ok' 46 | 47 | task :default => :cucumber 48 | 49 | task :features => :cucumber do 50 | STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***" 51 | end 52 | 53 | # In case we don't have ActiveRecord, append a no-op task that we can depend upon. 54 | task 'db:test:prepare' do 55 | end 56 | 57 | task :stats => 'cucumber:statsetup' 58 | rescue LoadError 59 | desc 'cucumber rake task not available (cucumber not installed)' 60 | task :cucumber do 61 | abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin' 62 | end 63 | end 64 | 65 | end 66 | -------------------------------------------------------------------------------- /log/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emilsoman/rails-4-api/ccda64743dc7bf46cf95c379e4be3dc809048935/log/.keep -------------------------------------------------------------------------------- /public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 48 | 49 | 50 | 51 | 52 |
53 |

The page you were looking for doesn't exist.

54 |

You may have mistyped the address or the page may have moved.

55 |
56 |

If you are the application owner check the logs for more information.

57 | 58 | 59 | -------------------------------------------------------------------------------- /public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 48 | 49 | 50 | 51 | 52 |
53 |

The change you wanted was rejected.

54 |

Maybe you tried to change something you didn't have access to.

55 |
56 |

If you are the application owner check the logs for more information.

57 | 58 | 59 | -------------------------------------------------------------------------------- /public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 48 | 49 | 50 | 51 | 52 |
53 |

We're sorry, but something went wrong.

54 |
55 |

If you are the application owner check the logs for more information.

56 | 57 | 58 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emilsoman/rails-4-api/ccda64743dc7bf46cf95c379e4be3dc809048935/public/favicon.ico -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file 2 | # 3 | # To ban all spiders from the entire site uncomment the next two lines: 4 | # User-agent: * 5 | # Disallow: / 6 | -------------------------------------------------------------------------------- /script/cucumber: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first 4 | if vendored_cucumber_bin 5 | load File.expand_path(vendored_cucumber_bin) 6 | else 7 | require 'rubygems' unless ENV['NO_RUBYGEMS'] 8 | require 'cucumber' 9 | load Cucumber::BINARY 10 | end 11 | -------------------------------------------------------------------------------- /spec/factories/users.rb: -------------------------------------------------------------------------------- 1 | FactoryGirl.define do 2 | factory :user do 3 | email "user@example.com" 4 | password "password123" 5 | password_confirmation "password123" 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/models/user_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe User do 4 | describe "#admin?" do 5 | let(:user) { FactoryGirl.create(:user, role: 'user') } 6 | context "when role is admin" do 7 | it "should return true" do 8 | user.role = 'admin' 9 | user.admin?.should be_true 10 | end 11 | end 12 | context "when role is user" do 13 | it "should return false" do 14 | user.role = 'user' 15 | user.admin?.should be_false 16 | end 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # This file is copied to spec/ when you run 'rails generate rspec:install' 2 | ENV["RAILS_ENV"] ||= 'test' 3 | require File.expand_path("../../config/environment", __FILE__) 4 | require 'rspec/rails' 5 | require 'rspec/autorun' 6 | 7 | # Requires supporting ruby files with custom matchers and macros, etc, 8 | # in spec/support/ and its subdirectories. 9 | Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } 10 | 11 | # Checks for pending migrations before tests are run. 12 | # If you are not using ActiveRecord, you can remove this line. 13 | ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration) 14 | 15 | RSpec.configure do |config| 16 | # ## Mock Framework 17 | # 18 | # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: 19 | # 20 | # config.mock_with :mocha 21 | # config.mock_with :flexmock 22 | # config.mock_with :rr 23 | 24 | # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures 25 | config.fixture_path = "#{::Rails.root}/spec/fixtures" 26 | 27 | # If you're not using ActiveRecord, or you'd prefer not to run each of your 28 | # examples within a transaction, remove the following line or assign false 29 | # instead of true. 30 | config.use_transactional_fixtures = true 31 | 32 | # If true, the base class of anonymous controllers will be inferred 33 | # automatically. This will be the default behavior in future versions of 34 | # rspec-rails. 35 | config.infer_base_class_for_anonymous_controllers = false 36 | 37 | # Run specs in random order to surface order dependencies. If you find an 38 | # order dependency and want to debug it, you can fix the order by providing 39 | # the seed, which is printed after each run. 40 | # --seed 1234 41 | config.order = "random" 42 | end 43 | -------------------------------------------------------------------------------- /vendor/assets/javascripts/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emilsoman/rails-4-api/ccda64743dc7bf46cf95c379e4be3dc809048935/vendor/assets/javascripts/.keep -------------------------------------------------------------------------------- /vendor/assets/stylesheets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emilsoman/rails-4-api/ccda64743dc7bf46cf95c379e4be3dc809048935/vendor/assets/stylesheets/.keep --------------------------------------------------------------------------------