├── .gitignore
├── .powenv
├── .ruby-gemset
├── .ruby-version
├── Gemfile
├── Gemfile.lock
├── LICENSE
├── README.md
├── README.rdoc
├── Rakefile
├── app
├── assets
│ ├── images
│ │ └── .keep
│ ├── javascripts
│ │ ├── application.js
│ │ ├── dreams.js.coffee
│ │ └── users.js.coffee
│ └── stylesheets
│ │ ├── application.css
│ │ ├── dreams.css.scss
│ │ └── users.css.scss
├── controllers
│ ├── api
│ │ ├── base_controller.rb
│ │ ├── v1
│ │ │ ├── base_controller.rb
│ │ │ ├── dreams_controller.rb
│ │ │ └── users_controller.rb
│ │ └── v2
│ │ │ ├── base_controller.rb
│ │ │ └── fake_controller.rb
│ ├── application_controller.rb
│ └── concerns
│ │ └── .keep
├── helpers
│ ├── application_helper.rb
│ ├── dreams_helper.rb
│ └── users_helper.rb
├── mailers
│ └── .keep
├── models
│ ├── .keep
│ ├── concerns
│ │ ├── .keep
│ │ └── searchable.rb
│ ├── dream.rb
│ └── user.rb
└── views
│ ├── api
│ ├── v1
│ │ ├── dreams
│ │ │ ├── index.rabl
│ │ │ └── show.rabl
│ │ └── users
│ │ │ ├── index.rabl
│ │ │ └── show.rabl
│ └── v2
│ │ └── fake
│ │ ├── fast.rabl
│ │ ├── normal.rabl
│ │ └── slow.rabl
│ └── layouts
│ └── application.html.erb
├── bin
├── bundle
├── rails
└── rake
├── config.ru
├── config
├── application.rb
├── boot.rb
├── database.yml
├── environment.rb
├── environments
│ ├── development.rb
│ ├── production.rb
│ └── test.rb
├── initializers
│ ├── assets.rb
│ ├── backtrace_silencers.rb
│ ├── cookies_serializer.rb
│ ├── filter_parameter_logging.rb
│ ├── inflections.rb
│ ├── mime_types.rb
│ ├── rabl.rb
│ ├── session_store.rb
│ └── wrap_parameters.rb
├── locales
│ └── en.yml
└── routes.rb
├── db
├── migrate
│ ├── 20141008172130_create_users.rb
│ └── 20141008172700_create_dreams.rb
├── schema.rb
└── seeds.rb
├── lib
├── assets
│ └── .keep
└── tasks
│ ├── .keep
│ └── elasticsearch.rake
├── public
├── 404.html
├── 422.html
├── 500.html
├── favicon.ico
└── robots.txt
├── test
├── controllers
│ └── .keep
├── factories
│ ├── dreams.rb
│ └── users.rb
├── fixtures
│ └── .keep
├── helpers
│ ├── .keep
│ ├── dreams_helper_test.rb
│ └── users_helper_test.rb
├── integration
│ ├── .keep
│ ├── dreams
│ │ ├── creating_dreams_test.rb
│ │ ├── deleting_dreams_test.rb
│ │ ├── listing_dreams_test.rb
│ │ └── updating_dreams_test.rb
│ ├── routes_test.rb
│ └── users
│ │ ├── creating_users_test.rb
│ │ ├── deleting_users_test.rb
│ │ ├── listing_users_test.rb
│ │ └── updating_users_test.rb
├── mailers
│ └── .keep
├── models
│ ├── .keep
│ ├── dream_test.rb
│ └── user_test.rb
└── test_helper.rb
└── vendor
└── assets
├── javascripts
└── .keep
└── stylesheets
└── .keep
/.gitignore:
--------------------------------------------------------------------------------
1 | touch*.rbc
2 | capybara-*.html
3 | .rspec
4 | /log
5 | /tmp
6 | /db/*.sqlite3
7 | /public/system
8 | /coverage/
9 | /spec/tmp
10 | **.orig
11 | rerun.txt
12 | pickle-email-*.html
13 |
14 | # TODO Comment out these rules if you are OK with secrets being uploaded to the repo
15 | config/initializers/secret_token.rb
16 | config/secrets.yml
17 |
18 | ## Environment normalisation:
19 | /.bundle
20 | /vendor/bundle
21 |
22 | # these should all be checked in to normalise the environment:
23 | # Gemfile.lock, .ruby-version, .ruby-gemset
24 |
25 | # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
26 | .rvmrc
27 |
28 | # if using bower-rails ignore default bower_components path bower.json files
29 | /vendor/assets/bower_components
30 | *.bowerrc
31 | bower.json
32 |
--------------------------------------------------------------------------------
/.powenv:
--------------------------------------------------------------------------------
1 | /Users/cody/.powenv
--------------------------------------------------------------------------------
/.ruby-gemset:
--------------------------------------------------------------------------------
1 | rest-api
2 |
--------------------------------------------------------------------------------
/.ruby-version:
--------------------------------------------------------------------------------
1 | 2.3.1
2 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 | ruby '2.3.1'
3 |
4 | gem 'rails', '4.2'
5 | gem 'pg'
6 | gem 'puma'
7 |
8 | gem 'sass-rails'
9 | gem 'uglifier'
10 | gem 'coffee-rails'
11 | gem 'jquery-rails'
12 | gem 'turbolinks'
13 |
14 | gem 'rabl' # API builder
15 | gem 'oj' # JSON parser
16 | gem 'httparty' # Makes http requests incredibly easy
17 |
18 | gem 'kaminari' # adds pagination to ActiveModels
19 | gem 'elasticsearch-model'
20 | gem 'elasticsearch-rails'
21 | gem 'responders', '~> 2.0'
22 |
23 | # gem 'sdoc', '~> 0.4.0', group: :doc
24 |
25 | group :development do
26 | #gem 'powder'
27 | # gem 'better_errors'
28 | # gem 'binding_of_caller', :platforms=>[:mri_21]
29 | # gem 'meta_request'
30 | # gem 'xray-rails'
31 |
32 | # gem 'guard'
33 | # gem 'guard-bundler'
34 | # gem 'guard-minitest'
35 | # gem 'guard-pow'
36 | # gem 'guard-livereload'
37 | # gem 'rack-livereload'
38 | # gem 'ruby_gntp'
39 |
40 | # gem 'html2haml'
41 | # gem 'quiet_assets'
42 | # gem 'spring'
43 | end
44 |
45 | group :development, :test do
46 | # gem 'jazz_hands'
47 | gem 'ffaker'
48 | gem 'factory_girl_rails'
49 | end
50 |
51 | group :test do
52 | gem 'simplecov', :require => false
53 | end
54 |
--------------------------------------------------------------------------------
/Gemfile.lock:
--------------------------------------------------------------------------------
1 | GEM
2 | remote: https://rubygems.org/
3 | specs:
4 | actionmailer (4.2.0)
5 | actionpack (= 4.2.0)
6 | actionview (= 4.2.0)
7 | activejob (= 4.2.0)
8 | mail (~> 2.5, >= 2.5.4)
9 | rails-dom-testing (~> 1.0, >= 1.0.5)
10 | actionpack (4.2.0)
11 | actionview (= 4.2.0)
12 | activesupport (= 4.2.0)
13 | rack (~> 1.6.0)
14 | rack-test (~> 0.6.2)
15 | rails-dom-testing (~> 1.0, >= 1.0.5)
16 | rails-html-sanitizer (~> 1.0, >= 1.0.1)
17 | actionview (4.2.0)
18 | activesupport (= 4.2.0)
19 | builder (~> 3.1)
20 | erubis (~> 2.7.0)
21 | rails-dom-testing (~> 1.0, >= 1.0.5)
22 | rails-html-sanitizer (~> 1.0, >= 1.0.1)
23 | activejob (4.2.0)
24 | activesupport (= 4.2.0)
25 | globalid (>= 0.3.0)
26 | activemodel (4.2.0)
27 | activesupport (= 4.2.0)
28 | builder (~> 3.1)
29 | activerecord (4.2.0)
30 | activemodel (= 4.2.0)
31 | activesupport (= 4.2.0)
32 | arel (~> 6.0)
33 | activesupport (4.2.0)
34 | i18n (~> 0.7)
35 | json (~> 1.7, >= 1.7.7)
36 | minitest (~> 5.1)
37 | thread_safe (~> 0.3, >= 0.3.4)
38 | tzinfo (~> 1.1)
39 | arel (6.0.3)
40 | builder (3.2.2)
41 | coffee-rails (4.2.1)
42 | coffee-script (>= 2.2.0)
43 | railties (>= 4.0.0, < 5.2.x)
44 | coffee-script (2.4.1)
45 | coffee-script-source
46 | execjs
47 | coffee-script-source (1.10.0)
48 | concurrent-ruby (1.0.2)
49 | docile (1.1.5)
50 | elasticsearch (2.0.0)
51 | elasticsearch-api (= 2.0.0)
52 | elasticsearch-transport (= 2.0.0)
53 | elasticsearch-api (2.0.0)
54 | multi_json
55 | elasticsearch-model (0.1.9)
56 | activesupport (> 3)
57 | elasticsearch (> 0.4)
58 | hashie
59 | elasticsearch-rails (0.1.9)
60 | elasticsearch-transport (2.0.0)
61 | faraday
62 | multi_json
63 | erubis (2.7.0)
64 | execjs (2.7.0)
65 | factory_girl (4.7.0)
66 | activesupport (>= 3.0.0)
67 | factory_girl_rails (4.7.0)
68 | factory_girl (~> 4.7.0)
69 | railties (>= 3.0.0)
70 | faraday (0.9.2)
71 | multipart-post (>= 1.2, < 3)
72 | ffaker (2.2.0)
73 | globalid (0.3.7)
74 | activesupport (>= 4.1.0)
75 | hashie (3.4.4)
76 | httparty (0.14.0)
77 | multi_xml (>= 0.5.2)
78 | i18n (0.7.0)
79 | jquery-rails (4.2.1)
80 | rails-dom-testing (>= 1, < 3)
81 | railties (>= 4.2.0)
82 | thor (>= 0.14, < 2.0)
83 | json (1.8.3)
84 | kaminari (0.17.0)
85 | actionpack (>= 3.0.0)
86 | activesupport (>= 3.0.0)
87 | loofah (2.0.3)
88 | nokogiri (>= 1.5.9)
89 | mail (2.6.4)
90 | mime-types (>= 1.16, < 4)
91 | mime-types (3.1)
92 | mime-types-data (~> 3.2015)
93 | mime-types-data (3.2016.0521)
94 | mini_portile2 (2.1.0)
95 | minitest (5.9.0)
96 | multi_json (1.12.1)
97 | multi_xml (0.5.5)
98 | multipart-post (2.0.0)
99 | nokogiri (1.6.8)
100 | mini_portile2 (~> 2.1.0)
101 | pkg-config (~> 1.1.7)
102 | oj (2.17.3)
103 | pg (0.18.4)
104 | pkg-config (1.1.7)
105 | puma (3.6.0)
106 | rabl (0.13.0)
107 | activesupport (>= 2.3.14)
108 | rack (1.6.4)
109 | rack-test (0.6.3)
110 | rack (>= 1.0)
111 | rails (4.2.0)
112 | actionmailer (= 4.2.0)
113 | actionpack (= 4.2.0)
114 | actionview (= 4.2.0)
115 | activejob (= 4.2.0)
116 | activemodel (= 4.2.0)
117 | activerecord (= 4.2.0)
118 | activesupport (= 4.2.0)
119 | bundler (>= 1.3.0, < 2.0)
120 | railties (= 4.2.0)
121 | sprockets-rails
122 | rails-deprecated_sanitizer (1.0.3)
123 | activesupport (>= 4.2.0.alpha)
124 | rails-dom-testing (1.0.7)
125 | activesupport (>= 4.2.0.beta, < 5.0)
126 | nokogiri (~> 1.6.0)
127 | rails-deprecated_sanitizer (>= 1.0.1)
128 | rails-html-sanitizer (1.0.3)
129 | loofah (~> 2.0)
130 | railties (4.2.0)
131 | actionpack (= 4.2.0)
132 | activesupport (= 4.2.0)
133 | rake (>= 0.8.7)
134 | thor (>= 0.18.1, < 2.0)
135 | rake (11.2.2)
136 | responders (2.3.0)
137 | railties (>= 4.2.0, < 5.1)
138 | sass (3.4.22)
139 | sass-rails (5.0.6)
140 | railties (>= 4.0.0, < 6)
141 | sass (~> 3.1)
142 | sprockets (>= 2.8, < 4.0)
143 | sprockets-rails (>= 2.0, < 4.0)
144 | tilt (>= 1.1, < 3)
145 | simplecov (0.12.0)
146 | docile (~> 1.1.0)
147 | json (>= 1.8, < 3)
148 | simplecov-html (~> 0.10.0)
149 | simplecov-html (0.10.0)
150 | sprockets (3.7.0)
151 | concurrent-ruby (~> 1.0)
152 | rack (> 1, < 3)
153 | sprockets-rails (3.1.1)
154 | actionpack (>= 4.0)
155 | activesupport (>= 4.0)
156 | sprockets (>= 3.0.0)
157 | thor (0.19.1)
158 | thread_safe (0.3.5)
159 | tilt (2.0.5)
160 | turbolinks (5.0.1)
161 | turbolinks-source (~> 5)
162 | turbolinks-source (5.0.0)
163 | tzinfo (1.2.2)
164 | thread_safe (~> 0.1)
165 | uglifier (3.0.1)
166 | execjs (>= 0.3.0, < 3)
167 |
168 | PLATFORMS
169 | ruby
170 |
171 | DEPENDENCIES
172 | coffee-rails
173 | elasticsearch-model
174 | elasticsearch-rails
175 | factory_girl_rails
176 | ffaker
177 | httparty
178 | jquery-rails
179 | kaminari
180 | oj
181 | pg
182 | puma
183 | rabl
184 | rails (= 4.2)
185 | responders (~> 2.0)
186 | sass-rails
187 | simplecov
188 | turbolinks
189 | uglifier
190 |
191 | RUBY VERSION
192 | ruby 2.3.1p112
193 |
194 | BUNDLED WITH
195 | 1.12.5
196 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 CodyStringham
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | rest-api
2 | ========
3 |
4 | Welcome to my API homework app. Built upon this amazing [RESTful API blog post](https://codelation.com/blog/rails-restful-api-just-add-water). This API is versioned and set up with json:api standards using rabl.
5 |
6 | I've been getting a couple questions about how to get this setup and running, below are some dependancies you'll need:
7 |
8 | #### Subdomained and Versioned
9 | The version isn't a big deal, just prefix your requests with `/v1/`, but the subdomain can be tricky for beginners. You'll need to run a service like [Pow](pow.cx) to use subdomains in development. You can pair this with the ruby gem [Powder](https://github.com/Rodreegez/powder) for some really awesome times :)
10 |
11 | After you have these set up, you can successfully go to a url like `api.rest-api.dev/v1/dreams`
12 |
13 | #### Tests!
14 | There are also some really basic api tests written from codeschools rest api course, try them out with `rake test`
15 |
16 | What's inside of the app
17 | --------
18 | #### Models
19 | ```ruby
20 | User :name, :age, :city, :state
21 | Dream :date, :category, :description, :user_id
22 | ```
23 |
24 | #### Views
25 | `views/api/v1/dreams` & `views/api/v1/users` contain a index and show
26 |
27 | #### Controllers
28 | `controllers/api/v1/base_controller` contains the most logic, see private method comments. These will set and get the resource names as needed for each controller.
29 |
30 | #### Kaminari Pagination
31 | Kaminari has a default page size of 25, to override this pass in a `page` and/or a `page_size` paramater like the following:
32 | ```
33 | http://api.rest-api.dev/v1/dreams.json?page=1&page_size=10
34 | ```
35 |
36 | #### Built in query params
37 | Each controller has permitted query params, by default they are all allowed:
38 | ```
39 | http://api.rest-api.dev/v1/dreams.json?user_id=5&category=Nightmare
40 | ```
41 |
42 |
43 | Lets make a call!
44 | --------
45 | #### HTTParty Get
46 | ```ruby
47 | HTTParty.get 'http://api.rest-api.dev/v1/users.json'
48 | ```
49 |
50 | #### HTTParty Post
51 | ```ruby
52 | HTTParty.post('http://api.rest-api.dev/v1/users', body: { user: {name: "Json", age: "22", city: "Plainsville", state: "NV"} })
53 | ```
54 |
55 | #### HTTParty Patch
56 | ```ruby
57 | HTTParty.patch('http://api.rest-api.dev/v1/users/4', body: { user: {name: "Jason"} })
58 | ```
59 |
60 | #### HTTParty Delete
61 | ```ruby
62 | HTTParty.delete 'http://api.rest-api.dev/v1/users/4'
63 | ```
64 |
--------------------------------------------------------------------------------
/README.rdoc:
--------------------------------------------------------------------------------
1 | == README
2 |
3 | This README would normally document whatever steps are necessary to get the
4 | application up and running.
5 |
6 | Things you may want to cover:
7 |
8 | * Ruby version
9 |
10 | * System dependencies
11 |
12 | * Configuration
13 |
14 | * Database creation
15 |
16 | * Database initialization
17 |
18 | * How to run the test suite
19 |
20 | * Services (job queues, cache servers, search engines, etc.)
21 |
22 | * Deployment instructions
23 |
24 | * ...
25 |
26 |
27 | Please feel free to use a different markup language if you do not plan to run
28 | rake doc:app.
29 |
--------------------------------------------------------------------------------
/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 | Rails.application.load_tasks
7 |
--------------------------------------------------------------------------------
/app/assets/images/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodyStringham/rest-api/32f5767da6634a50e093bf68358de00da22d0039/app/assets/images/.keep
--------------------------------------------------------------------------------
/app/assets/javascripts/application.js:
--------------------------------------------------------------------------------
1 | // This is a manifest file that'll be compiled into application.js, which will include all the files
2 | // listed below.
3 | //
4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5 | // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6 | //
7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8 | // compiled file.
9 | //
10 | // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11 | // about supported directives.
12 | //
13 | //= require jquery
14 | //= require jquery_ujs
15 | //= require turbolinks
16 | //= require_tree .
17 |
--------------------------------------------------------------------------------
/app/assets/javascripts/dreams.js.coffee:
--------------------------------------------------------------------------------
1 | # Place all the behaviors and hooks related to the matching controller here.
2 | # All this logic will automatically be available in application.js.
3 | # You can use CoffeeScript in this file: http://coffeescript.org/
4 |
--------------------------------------------------------------------------------
/app/assets/javascripts/users.js.coffee:
--------------------------------------------------------------------------------
1 | # Place all the behaviors and hooks related to the matching controller here.
2 | # All this logic will automatically be available in application.js.
3 | # You can use CoffeeScript in this file: http://coffeescript.org/
4 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/application.css:
--------------------------------------------------------------------------------
1 | /*
2 | * This is a manifest file that'll be compiled into application.css, which will include all the files
3 | * listed below.
4 | *
5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6 | * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7 | *
8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9 | * compiled file so the styles you add here take precedence over styles defined in any styles
10 | * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11 | * file per style scope.
12 | *
13 | *= require_tree .
14 | *= require_self
15 | */
16 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/dreams.css.scss:
--------------------------------------------------------------------------------
1 | // Place all the styles related to the dreams controller here.
2 | // They will automatically be included in application.css.
3 | // You can use Sass (SCSS) here: http://sass-lang.com/
4 |
--------------------------------------------------------------------------------
/app/assets/stylesheets/users.css.scss:
--------------------------------------------------------------------------------
1 | // Place all the styles related to the users controller here.
2 | // They will automatically be included in application.css.
3 | // You can use Sass (SCSS) here: http://sass-lang.com/
4 |
--------------------------------------------------------------------------------
/app/controllers/api/base_controller.rb:
--------------------------------------------------------------------------------
1 | class Api::BaseController < ApplicationController
2 | respond_to :json, :xml
3 | end
4 |
--------------------------------------------------------------------------------
/app/controllers/api/v1/base_controller.rb:
--------------------------------------------------------------------------------
1 | class Api::V1::BaseController < Api::BaseController
2 | before_action :set_resource, only: [:destroy, :show, :update]
3 |
4 | # GET /api/v1/{plural_resource_name}
5 | def index
6 | plural_resource_name = "@#{resource_name.pluralize}"
7 | resources = resource_class.where(query_params)
8 | .page(page_params[:page])
9 | .per(page_params[:page_size])
10 |
11 | instance_variable_set(plural_resource_name, resources)
12 | respond_with instance_variable_get(plural_resource_name)
13 | end
14 |
15 | # GET /api/v1/{plural_resource_name}/1
16 | def show
17 | respond_with get_resource
18 | end
19 |
20 | def create
21 | set_resource(resource_class.new(resource_params))
22 |
23 | if get_resource.save
24 | render :show, status: :created, location: get_resource
25 | else
26 | render json: get_resource.errors, status: :unprocessable_entity
27 | end
28 | end
29 |
30 | # PATCH/PUT /api/v1/{plural_resource_name}/1
31 | def update
32 | if get_resource.update(resource_params)
33 | render :show
34 | else
35 | render json: get_resource.errors, status: :unprocessable_entity
36 | end
37 | end
38 |
39 | # DELETE /api/v1/{plural_resource_name}/1
40 | def destroy
41 | get_resource.destroy
42 | head :no_content
43 | end
44 |
45 | private
46 |
47 | # Returns the resource from the created instance variable
48 | # @return [Object]
49 | def get_resource
50 | instance_variable_get("@#{resource_name}")
51 | end
52 |
53 | # Returns the allowed parameters for searching
54 | # Override this method in each API controller
55 | # to permit additional parameters to search on
56 | # @return [Hash]
57 | def query_params
58 | {}
59 | end
60 |
61 | # Returns the allowed parameters for pagination
62 | # @return [Hash]
63 | def page_params
64 | params.permit(:page, :page_size)
65 | end
66 |
67 | # The resource class based on the controller
68 | # @return [Class]
69 | def resource_class
70 | @resource_class ||= resource_name.classify.constantize
71 | end
72 |
73 | # The singular name for the resource class based on the controller
74 | # @return [String]
75 | def resource_name
76 | @resource_name ||= self.controller_name.singularize
77 | end
78 |
79 | # Only allow a trusted parameter "white list" through.
80 | # If a single resource is loaded for #create or #update,
81 | # then the controller for the resource must implement
82 | # the method "#{resource_name}_params" to limit permitted
83 | # parameters for the individual model.
84 | def resource_params
85 | @resource_params ||= self.send("#{resource_name}_params")
86 | end
87 |
88 | # Use callbacks to share common setup or constraints between actions.
89 | def set_resource(resource = nil)
90 | resource ||= resource_class.find(params[:id])
91 | instance_variable_set("@#{resource_name}", resource)
92 | end
93 | end
94 |
--------------------------------------------------------------------------------
/app/controllers/api/v1/dreams_controller.rb:
--------------------------------------------------------------------------------
1 | class Api::V1::DreamsController < Api::V1::BaseController
2 |
3 | private
4 |
5 | def dream_params
6 | params.require(:dream).permit(:date, :category, :description, :user_id)
7 | end
8 |
9 | def query_params
10 | # this assumes that a dream belongs to a user and has an :user_id
11 | # allowing us to filter by this
12 | params.permit(:user_id, :date, :category, :description)
13 | end
14 |
15 | end
16 |
17 |
--------------------------------------------------------------------------------
/app/controllers/api/v1/users_controller.rb:
--------------------------------------------------------------------------------
1 | class Api::V1::UsersController < Api::V1::BaseController
2 |
3 | private
4 |
5 | def user_params
6 | params.require(:user).permit(:name, :age, :city, :state)
7 | end
8 |
9 | def query_params
10 | params.permit(:name, :age, :city, :state)
11 | end
12 |
13 | end
14 |
15 |
--------------------------------------------------------------------------------
/app/controllers/api/v2/base_controller.rb:
--------------------------------------------------------------------------------
1 | class Api::V2::BaseController < Api::BaseController
2 | # before_action :set_resource, only: [:destroy, :show, :update]
3 |
4 | end
5 |
--------------------------------------------------------------------------------
/app/controllers/api/v2/fake_controller.rb:
--------------------------------------------------------------------------------
1 | class Api::V2::FakeController < Api::V2::BaseController
2 |
3 | def fast
4 | end
5 |
6 | def normal
7 | sleep 1.5
8 | end
9 |
10 | def slow
11 | sleep 3
12 | end
13 |
14 | end
15 |
16 |
--------------------------------------------------------------------------------
/app/controllers/application_controller.rb:
--------------------------------------------------------------------------------
1 | class ApplicationController < ActionController::Base
2 | # Prevent CSRF attacks by raising an exception.
3 | # For APIs, you may want to use :null_session instead.
4 | protect_from_forgery with: :null_session
5 |
6 | end
7 |
--------------------------------------------------------------------------------
/app/controllers/concerns/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodyStringham/rest-api/32f5767da6634a50e093bf68358de00da22d0039/app/controllers/concerns/.keep
--------------------------------------------------------------------------------
/app/helpers/application_helper.rb:
--------------------------------------------------------------------------------
1 | module ApplicationHelper
2 | end
3 |
--------------------------------------------------------------------------------
/app/helpers/dreams_helper.rb:
--------------------------------------------------------------------------------
1 | module DreamsHelper
2 | end
3 |
--------------------------------------------------------------------------------
/app/helpers/users_helper.rb:
--------------------------------------------------------------------------------
1 | module UsersHelper
2 | end
3 |
--------------------------------------------------------------------------------
/app/mailers/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodyStringham/rest-api/32f5767da6634a50e093bf68358de00da22d0039/app/mailers/.keep
--------------------------------------------------------------------------------
/app/models/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodyStringham/rest-api/32f5767da6634a50e093bf68358de00da22d0039/app/models/.keep
--------------------------------------------------------------------------------
/app/models/concerns/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodyStringham/rest-api/32f5767da6634a50e093bf68358de00da22d0039/app/models/concerns/.keep
--------------------------------------------------------------------------------
/app/models/concerns/searchable.rb:
--------------------------------------------------------------------------------
1 | module Searchable
2 | extend ActiveSupport::Concern
3 |
4 | included do
5 | include Elasticsearch::Model
6 | include Elasticsearch::Model::Callbacks
7 |
8 | Kaminari::Hooks.init
9 | Elasticsearch::Model::Response::Response.__send__ :include, Elasticsearch::Model::Response::Pagination::Kaminari
10 |
11 | # mapping do
12 | # # ...
13 | # end
14 |
15 | # def self.search(query)
16 | # __elasticsearch__.search(
17 | # {
18 | # query: {
19 | # multi_match: {
20 | # query: query,
21 | # fields: ['title^10', 'text']
22 | # }
23 | # },
24 | # highlight: {
25 | # pre_tags: [''],
26 | # post_tags: [''],
27 | # fields: {
28 | # title: {},
29 | # text: {}
30 | # }
31 | # }
32 | # }
33 | # )
34 | # end
35 |
36 | end
37 | end
38 |
--------------------------------------------------------------------------------
/app/models/dream.rb:
--------------------------------------------------------------------------------
1 | class Dream < ActiveRecord::Base
2 | include Searchable
3 | belongs_to :user
4 | validates :user_id, :date, :category, :description, presence: true
5 | validates_inclusion_of :category, :in => %w( Fantasy Psychic Nightmare Surreal )
6 |
7 | def as_indexed_json(options={})
8 | as_json(
9 | include: {
10 | user: { only: :name }
11 | }
12 | )
13 | end
14 | end
15 |
16 |
17 | # '{
18 | # "query": {
19 | # "match": {
20 | # "category": "Nightmare"
21 | # }
22 | # }
23 | # }'
24 | # '{"query": {"match": {"category": "Nightmare"} } }'
25 |
26 | # '{
27 | # "query": {
28 | # "bool": {
29 | # "must": {
30 | # "match": {
31 | # "category": "Nightmare"
32 | # }
33 | # },
34 | # "should": {
35 | # "match": {
36 | # "description": "molestiae"
37 | # }
38 | # }
39 | # }
40 | # }
41 | # }'
42 | # '{"query": {"bool": {"must": {"match": {"category": "Nightmare"} }, "should": {"match": {"description": "molestiae"} } } } }'
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/app/models/user.rb:
--------------------------------------------------------------------------------
1 | class User < ActiveRecord::Base
2 | include Searchable
3 |
4 | has_many :dreams, dependent: :destroy
5 | validates :name, :age, :city, :state, presence: true
6 | validates_inclusion_of :age, :in => 0..99
7 |
8 |
9 | def as_indexed_json(options={})
10 | as_json(
11 | include: {
12 | dreams: { only: [:category, :description] }
13 | }
14 | )
15 | end
16 | end
17 |
--------------------------------------------------------------------------------
/app/views/api/v1/dreams/index.rabl:
--------------------------------------------------------------------------------
1 | collection @dreams => :dreams
2 |
3 | extends 'api/v1/dreams/show'
4 |
--------------------------------------------------------------------------------
/app/views/api/v1/dreams/show.rabl:
--------------------------------------------------------------------------------
1 | collection [@dream] => :dreams
2 |
3 | attributes :id, :category, :description, :user_id
4 | node(:date){|dream| dream.date.strftime("%m/%d/%y")}
5 |
6 | node :links do |dream|
7 | links = {}
8 | if params['action'] == 'index'
9 | links[:show_dream] = api_v1_dream_url(dream.id)
10 | else
11 | links[:all_dreams] = api_v1_dreams_url
12 | end
13 | links
14 | end
15 |
16 | child :user do
17 | attributes :id, :name, :age, :city, :state
18 | node :links do |user|
19 | links = {}
20 | links[:show_user] = api_v1_user_url(user.id)
21 | links[:all_users] = api_v1_users_url
22 | links
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/app/views/api/v1/users/index.rabl:
--------------------------------------------------------------------------------
1 | collection @users => :users
2 |
3 | extends 'api/v1/users/show'
4 |
--------------------------------------------------------------------------------
/app/views/api/v1/users/show.rabl:
--------------------------------------------------------------------------------
1 | collection [@user] => :users
2 |
3 | attributes :id, :name, :age, :city, :state
4 |
5 | node :links do |user|
6 | links = {}
7 | if params['action'] == 'index'
8 | links[:show_user] = api_v1_user_url(user.id)
9 | else
10 | links[:all_users] = api_v1_users_url
11 | end
12 | links
13 | end
14 |
15 | child :dreams do
16 | attributes :id, :category, :description
17 | node(:date){|date| date.date.strftime("%m/%d/%y")}
18 | node :links do |dream|
19 | links = {}
20 | links[:show_dream] = api_v1_dream_url(dream.id)
21 | links[:all_dreams] = api_v1_dreams_url
22 | links
23 | end
24 | end
25 |
--------------------------------------------------------------------------------
/app/views/api/v2/fake/fast.rabl:
--------------------------------------------------------------------------------
1 | object false
2 |
3 | node do
4 | {
5 | speed: 'fast'
6 | }
7 | end
8 |
--------------------------------------------------------------------------------
/app/views/api/v2/fake/normal.rabl:
--------------------------------------------------------------------------------
1 | object false
2 |
3 | node do
4 | {
5 | speed: 'normal'
6 | }
7 | end
8 |
--------------------------------------------------------------------------------
/app/views/api/v2/fake/slow.rabl:
--------------------------------------------------------------------------------
1 | object false
2 |
3 | node do
4 | {
5 | speed: 'slow'
6 | }
7 | end
8 |
--------------------------------------------------------------------------------
/app/views/layouts/application.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | RestApi
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(*Rails.groups)
8 |
9 | module RestApi
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.exist?(ENV['BUNDLE_GEMFILE'])
5 |
--------------------------------------------------------------------------------
/config/database.yml:
--------------------------------------------------------------------------------
1 | # PostgreSQL. Versions 8.2 and up are supported.
2 | #
3 | # Install the pg driver:
4 | # gem install pg
5 | # On OS X with Homebrew:
6 | # gem install pg -- --with-pg-config=/usr/local/bin/pg_config
7 | # On OS X with MacPorts:
8 | # gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
9 | # On Windows:
10 | # gem install pg
11 | # Choose the win32 build.
12 | # Install PostgreSQL and put its /bin directory on your path.
13 | #
14 | # Configure Using Gemfile
15 | # gem 'pg'
16 | #
17 | default: &default
18 | adapter: postgresql
19 | encoding: unicode
20 | # For details on connection pooling, see rails configuration guide
21 | # http://guides.rubyonrails.org/configuring.html#database-pooling
22 | pool: 5
23 |
24 | development:
25 | <<: *default
26 | database: rest-api_development
27 |
28 | # The specified database role being used to connect to postgres.
29 | # To create additional roles in postgres see `$ createuser --help`.
30 | # When left blank, postgres will use the default role. This is
31 | # the same name as the operating system user that initialized the database.
32 | #username: rest-api
33 |
34 | # The password associated with the postgres role (username).
35 | #password:
36 |
37 | # Connect on a TCP socket. Omitted by default since the client uses a
38 | # domain socket that doesn't need configuration. Windows does not have
39 | # domain sockets, so uncomment these lines.
40 | #host: localhost
41 |
42 | # The TCP port the server listens on. Defaults to 5432.
43 | # If your server runs on a different port number, change accordingly.
44 | #port: 5432
45 |
46 | # Schema search path. The server defaults to $user,public
47 | #schema_search_path: myapp,sharedapp,public
48 |
49 | # Minimum log levels, in increasing order:
50 | # debug5, debug4, debug3, debug2, debug1,
51 | # log, notice, warning, error, fatal, and panic
52 | # Defaults to warning.
53 | #min_messages: notice
54 |
55 | # Warning: The database defined as "test" will be erased and
56 | # re-generated from your development database when you run "rake".
57 | # Do not set this db to the same as development or production.
58 | test:
59 | <<: *default
60 | database: rest-api_test
61 |
62 | # As with config/secrets.yml, you never want to store sensitive information,
63 | # like your database password, in your source code. If your source code is
64 | # ever seen by anyone, they now have access to your database.
65 | #
66 | # Instead, provide the password as a unix environment variable when you boot
67 | # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
68 | # for a full rundown on how to provide these environment variables in a
69 | # production deployment.
70 | #
71 | # On Heroku and other platform providers, you may have a full connection URL
72 | # available as an environment variable. For example:
73 | #
74 | # DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
75 | #
76 | # You can use this database configuration with:
77 | #
78 | # production:
79 | # url: <%= ENV['DATABASE_URL'] %>
80 | #
81 | production:
82 | <<: *default
83 | database: rest-api_production
84 | username: cody
85 | password: <%= ENV['REST-API_DATABASE_PASSWORD'] %>
86 |
--------------------------------------------------------------------------------
/config/environment.rb:
--------------------------------------------------------------------------------
1 | # Load the Rails application.
2 | require File.expand_path('../application', __FILE__)
3 |
4 | # Initialize the Rails application.
5 | Rails.application.initialize!
6 |
--------------------------------------------------------------------------------
/config/environments/development.rb:
--------------------------------------------------------------------------------
1 | Rails.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 |
30 | # Adds additional error checking when serving assets at runtime.
31 | # Checks for improperly declared sprockets dependencies.
32 | # Raises helpful error messages.
33 | config.assets.raise_runtime_errors = true
34 |
35 | # Raises error for missing translations
36 | # config.action_view.raise_on_missing_translations = true
37 | end
38 |
--------------------------------------------------------------------------------
/config/environments/production.rb:
--------------------------------------------------------------------------------
1 | Rails.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 threaded 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 | # `config.assets.precompile` has moved to config/initializers/assets.rb
36 |
37 | # Specifies the header that your server uses for sending files.
38 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
39 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
40 |
41 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
42 | # config.force_ssl = true
43 |
44 | # Set to :debug to see everything in the log.
45 | config.log_level = :info
46 |
47 | # Prepend all log lines with the following tags.
48 | # config.log_tags = [ :subdomain, :uuid ]
49 |
50 | # Use a different logger for distributed setups.
51 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
52 |
53 | # Use a different cache store in production.
54 | # config.cache_store = :mem_cache_store
55 |
56 | # Enable serving of images, stylesheets, and JavaScripts from an asset server.
57 | # config.action_controller.asset_host = "http://assets.example.com"
58 |
59 | # Precompile additional assets.
60 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
61 | # config.assets.precompile += %w( search.js )
62 |
63 | # Ignore bad email addresses and do not raise email delivery errors.
64 | # Set this to true and configure the email server for immediate delivery to raise delivery errors.
65 | # config.action_mailer.raise_delivery_errors = false
66 |
67 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
68 | # the I18n.default_locale when a translation cannot be found).
69 | config.i18n.fallbacks = true
70 |
71 | # Send deprecation notices to registered listeners.
72 | config.active_support.deprecation = :notify
73 |
74 | # Disable automatic flushing of the log to improve performance.
75 | # config.autoflush_log = false
76 |
77 | # Use default logging formatter so that PID and timestamp are not suppressed.
78 | config.log_formatter = ::Logger::Formatter.new
79 |
80 | # Do not dump schema after migrations.
81 | config.active_record.dump_schema_after_migration = false
82 | end
83 |
--------------------------------------------------------------------------------
/config/environments/test.rb:
--------------------------------------------------------------------------------
1 | Rails.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 |
37 | # Raises error for missing translations
38 | # config.action_view.raise_on_missing_translations = true
39 | end
40 |
--------------------------------------------------------------------------------
/config/initializers/assets.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Version of your assets, change this if you want to expire all your assets.
4 | Rails.application.config.assets.version = '1.0'
5 |
6 | # Precompile additional assets.
7 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
8 | # Rails.application.config.assets.precompile += %w( search.js )
9 |
--------------------------------------------------------------------------------
/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/cookies_serializer.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | Rails.application.config.action_dispatch.cookies_serializer = :json
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/config/initializers/rabl.rb:
--------------------------------------------------------------------------------
1 | # class that adds indentatino to json to make it more readable
2 | class PrettyJson
3 | def self.dump(object)
4 | JSON.pretty_generate(object, {:indent => " "})
5 | end
6 | end
7 |
8 | Rabl.configure do |config|
9 | config.include_json_root = false
10 | config.include_child_root = false
11 | config.json_engine = PrettyJson
12 | end
13 |
--------------------------------------------------------------------------------
/config/initializers/session_store.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | Rails.application.config.session_store :cookie_store, key: '_rest-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/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 | Rails.application.routes.draw do
2 |
3 |
4 |
5 | namespace :api, path: '/', constraints: { subdomain: 'api' } do
6 | namespace :v1 do
7 | resources :dreams, :users, except: [:new, :edit]
8 | end
9 | namespace :v2 do
10 | get "/fast", to: 'fake#fast', as: :fast
11 | get "/normal", to: 'fake#normal', as: :normal
12 | get "/slow", to: 'fake#slow', as: :slow
13 | end
14 | end
15 |
16 | # namespace path_helper hackery!
17 | get '/v1/dreams/:id', to: 'dreams#show', as: :dream
18 | get '/v1/users/:id', to: 'users#show', as: :user
19 |
20 | end
21 |
--------------------------------------------------------------------------------
/db/migrate/20141008172130_create_users.rb:
--------------------------------------------------------------------------------
1 | class CreateUsers < ActiveRecord::Migration
2 | def change
3 | create_table :users do |t|
4 | t.string :name
5 | t.integer :age
6 | t.string :city
7 | t.string :state
8 |
9 | t.timestamps
10 | end
11 | end
12 | end
13 |
--------------------------------------------------------------------------------
/db/migrate/20141008172700_create_dreams.rb:
--------------------------------------------------------------------------------
1 | class CreateDreams < ActiveRecord::Migration
2 | def change
3 | create_table :dreams do |t|
4 | t.datetime :date
5 | t.string :category
6 | t.text :description
7 | t.references :user, index: true
8 |
9 | t.timestamps
10 | end
11 | end
12 | end
13 |
--------------------------------------------------------------------------------
/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: 20141008172700) do
15 |
16 | # These are extensions that must be enabled in order to support this database
17 | enable_extension "plpgsql"
18 |
19 | create_table "dreams", force: true do |t|
20 | t.datetime "date"
21 | t.string "category"
22 | t.text "description"
23 | t.integer "user_id"
24 | t.datetime "created_at"
25 | t.datetime "updated_at"
26 | end
27 |
28 | add_index "dreams", ["user_id"], name: "index_dreams_on_user_id", using: :btree
29 |
30 | create_table "users", force: true do |t|
31 | t.string "name"
32 | t.integer "age"
33 | t.string "city"
34 | t.string "state"
35 | t.datetime "created_at"
36 | t.datetime "updated_at"
37 | end
38 |
39 | end
40 |
--------------------------------------------------------------------------------
/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 |
9 | 50.times do
10 | User.create!(name: "#{FFaker::Name.first_name}", age: rand(18..45), city: "#{FFaker::Address.city}", state: "#{FFaker::AddressUS.state_abbr}")
11 | end
12 |
13 | 250.times do
14 | Dream.create!(user_id: rand(1..50), date: Time.now - rand(100).days, category: ["Fantasy", "Nightmare", "Surreal", "Psychic"].sample, description: "#{FFaker::Lorem.phrase}")
15 | end
16 |
--------------------------------------------------------------------------------
/lib/assets/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodyStringham/rest-api/32f5767da6634a50e093bf68358de00da22d0039/lib/assets/.keep
--------------------------------------------------------------------------------
/lib/tasks/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodyStringham/rest-api/32f5767da6634a50e093bf68358de00da22d0039/lib/tasks/.keep
--------------------------------------------------------------------------------
/lib/tasks/elasticsearch.rake:
--------------------------------------------------------------------------------
1 | require 'elasticsearch/rails/tasks/import'
2 |
--------------------------------------------------------------------------------
/public/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The page you were looking for doesn't exist (404)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
The page you were looking for doesn't exist.
62 |
You may have mistyped the address or the page may have moved.
63 |
64 |
If you are the application owner check the logs for more information.
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/public/422.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The change you wanted was rejected (422)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
The change you wanted was rejected.
62 |
Maybe you tried to change something you didn't have access to.
63 |
64 |
If you are the application owner check the logs for more information.
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/public/500.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | We're sorry, but something went wrong (500)
5 |
6 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
We're sorry, but something went wrong.
62 |
63 |
If you are the application owner check the logs for more information.
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodyStringham/rest-api/32f5767da6634a50e093bf68358de00da22d0039/public/favicon.ico
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # See http://www.robotstxt.org/robotstxt.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 |
--------------------------------------------------------------------------------
/test/controllers/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodyStringham/rest-api/32f5767da6634a50e093bf68358de00da22d0039/test/controllers/.keep
--------------------------------------------------------------------------------
/test/factories/dreams.rb:
--------------------------------------------------------------------------------
1 | # Read about factories at https://github.com/thoughtbot/factory_girl
2 |
3 | FactoryGirl.define do
4 | factory :dream do |d|
5 | d.date { "#{Time.now}" }
6 | d.category { "#{ %w(Fantasy Psychic Nightmare Surreal).sample }" }
7 | d.description { "#{FFaker::Lorem.phrase}" }
8 | d.user { nil }
9 | end
10 | end
11 |
--------------------------------------------------------------------------------
/test/factories/users.rb:
--------------------------------------------------------------------------------
1 | # Read about factories at https://github.com/thoughtbot/factory_girl
2 |
3 | FactoryGirl.define do
4 | factory :user do |u|
5 | u.name { "#{FFaker::Name.first_name}" }
6 | u.age { rand(18..45) }
7 | u.city { "#{FFaker::Address.city}" }
8 | u.state { "#{FFaker::AddressUS.state_abbr}" }
9 | end
10 | end
11 |
--------------------------------------------------------------------------------
/test/fixtures/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodyStringham/rest-api/32f5767da6634a50e093bf68358de00da22d0039/test/fixtures/.keep
--------------------------------------------------------------------------------
/test/helpers/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodyStringham/rest-api/32f5767da6634a50e093bf68358de00da22d0039/test/helpers/.keep
--------------------------------------------------------------------------------
/test/helpers/dreams_helper_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class DreamsHelperTest < ActionView::TestCase
4 | end
5 |
--------------------------------------------------------------------------------
/test/helpers/users_helper_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class UsersHelperTest < ActionView::TestCase
4 | end
5 |
--------------------------------------------------------------------------------
/test/integration/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodyStringham/rest-api/32f5767da6634a50e093bf68358de00da22d0039/test/integration/.keep
--------------------------------------------------------------------------------
/test/integration/dreams/creating_dreams_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class CreatingDreamsTest < ActionDispatch::IntegrationTest
4 |
5 | setup do
6 | host! 'api.example.com' #required for testing with a subdomain constraint
7 | @user = create(:user)
8 | end
9 |
10 | test 'should create a dream' do
11 | post '/v1/dreams',
12 | { dream:
13 | { user_id: @user.id, date: Time.now, category: "Nightmare", description: "Dreams are cool!" }
14 | }.to_json,
15 | { 'Accept' => Mime::JSON, 'Content-Type' => Mime::JSON.to_s }
16 |
17 | assert_response :created
18 | assert_equal Mime::JSON, response.content_type
19 |
20 | data = JSON.parse(response.body)
21 | assert_equal api_v1_dream_url(data['dreams'].first['id']), response.location
22 | end
23 |
24 | test 'should not create a dream without a date' do
25 | post '/v1/dreams',
26 | { dream:
27 | { user_id: @user.id, date: nil, category: "Nightmare", description: "Dreams are cool!" }
28 | }.to_json,
29 | { 'Accept' => Mime::JSON, 'Content-Type' => Mime::JSON.to_s }
30 |
31 | assert_response :unprocessable_entity
32 | assert_equal Mime::JSON, response.content_type
33 | end
34 |
35 | test 'should not create a dream without an category' do
36 | post '/v1/dreams',
37 | { dream:
38 | { user_id: @user.id, date: Time.now, category: nil, description: "Dreams are cool!" }
39 | }.to_json,
40 | { 'Accept' => Mime::JSON, 'Content-Type' => Mime::JSON.to_s }
41 |
42 | assert_response :unprocessable_entity
43 | assert_equal Mime::JSON, response.content_type
44 | end
45 |
46 | test 'should not create a dream without a description' do
47 | post '/v1/dreams',
48 | { dream:
49 | { user_id: @user.id, date: Time.now, category: "Nightmare", description: nil }
50 | }.to_json,
51 | { 'Accept' => Mime::JSON, 'Content-Type' => Mime::JSON.to_s }
52 |
53 | assert_response :unprocessable_entity
54 | assert_equal Mime::JSON, response.content_type
55 | end
56 |
57 | test 'should not create a dream without a user' do
58 | post '/v1/dreams',
59 | { dream:
60 | { user_id: nil, date: Time.now, category: "Nightmare", description: "Dreams are cool!" }
61 | }.to_json,
62 | { 'Accept' => Mime::JSON, 'Content-Type' => Mime::JSON.to_s }
63 |
64 | assert_response :unprocessable_entity
65 | assert_equal Mime::JSON, response.content_type
66 | end
67 |
68 | end
69 |
--------------------------------------------------------------------------------
/test/integration/dreams/deleting_dreams_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class DeletingDreamsTest < ActionDispatch::IntegrationTest
4 |
5 | setup do
6 | host! 'api.example.com' #required for testing with a subdomain constraint
7 | @user = create(:user)
8 | @dream = create(:dream, user_id: @user.id)
9 | end
10 |
11 | test 'should delete a dream' do
12 | delete "/v1/dreams/#{@dream.id}"
13 | assert_response :no_content
14 | end
15 |
16 | end
17 |
--------------------------------------------------------------------------------
/test/integration/dreams/listing_dreams_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class ListingUsersTest < ActionDispatch::IntegrationTest
4 | setup do
5 | host! 'api.example.com' #required for testing with a subdomain constraint
6 | @user = create(:user)
7 | @user2 = create(:user)
8 | @dream1 = create(:dream, user_id: @user.id)
9 | @dream2 = create(:dream, user_id: @user2.id)
10 | end
11 |
12 | test 'should return a list of dreams' do
13 | get '/v1/dreams.json'
14 | assert_response :success
15 | refute_empty response.body
16 | end
17 |
18 | test 'should return dreams filtered by user_id' do
19 | get "/v1/dreams.json?user_id=#{@dream1.user_id}"
20 | assert_response :success
21 |
22 | data = JSON.parse(response.body)
23 | users = data['dreams'].collect { |u| u['user_id'] }
24 | assert_includes users, @dream1.user_id
25 | refute_includes users, @dream2.user_id
26 | end
27 |
28 | test 'should return a dream by id' do
29 | get "/v1/dreams/#{@dream1.id}.json"
30 | assert_response :success
31 |
32 | data = JSON.parse(response.body)
33 | assert_equal @dream1.id, data['dreams'].first['id']
34 | end
35 |
36 | test 'returns dreams in JSON' do
37 | get '/v1/dreams', {}, { accept: Mime::JSON }
38 | assert_response :success
39 | assert_equal Mime::JSON, response.content_type
40 | end
41 |
42 | test 'returns dreams in XML' do
43 | get '/v1/dreams', {}, { accept: Mime::XML }
44 | assert_response :success
45 | assert_equal Mime::XML, response.content_type
46 | end
47 |
48 | end
49 |
--------------------------------------------------------------------------------
/test/integration/dreams/updating_dreams_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class UpdatingDreamsTest < ActionDispatch::IntegrationTest
4 |
5 | setup do
6 | host! 'api.example.com' #required for testing with a subdomain constraint
7 | @user = create(:user)
8 | @dream = create(:dream, user_id: @user.id)
9 | end
10 |
11 | test 'should update a dream' do
12 | patch "/v1/dreams/#{@dream.id}",
13 | { dream:
14 | { category: "Nightmare" }
15 | }.to_json,
16 | { 'Accept' => Mime::JSON, 'Content-Type' => Mime::JSON.to_s }
17 |
18 | assert_response :success
19 | assert_equal 'Nightmare', @dream.reload.category
20 | end
21 |
22 | test 'should not update a dream with a invalid category' do
23 | patch "/v1/dreams/#{@dream.id}",
24 | { dream:
25 | { category: "Day" }
26 | }.to_json,
27 | { 'Accept' => Mime::JSON, 'Content-Type' => Mime::JSON.to_s }
28 |
29 | assert_response :unprocessable_entity
30 | end
31 |
32 | end
33 |
--------------------------------------------------------------------------------
/test/integration/routes_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class RoutesTest < ActionDispatch::IntegrationTest
4 |
5 | test 'routes use the correct version' do
6 | assert_generates '/v1/users', { controller: 'api/v1/users', action: 'index' }
7 | # assert_generates '/v2/users', { controller: 'api/v2/users', action: 'index' }
8 | end
9 |
10 | end
11 |
--------------------------------------------------------------------------------
/test/integration/users/creating_users_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class CreatingUsersTest < ActionDispatch::IntegrationTest
4 |
5 | setup do
6 | host! 'api.example.com' #required for testing with a subdomain constraint
7 | end
8 |
9 | test 'should create a user' do
10 | post '/v1/users',
11 | { user:
12 | { name: "Joe", age: 33, city: "Tulsa", state: "OK" }
13 | }.to_json,
14 | { 'Accept' => Mime::JSON, 'Content-Type' => Mime::JSON.to_s }
15 |
16 | assert_response :created
17 | assert_equal Mime::JSON, response.content_type
18 |
19 | data = JSON.parse(response.body)
20 | assert_equal api_v1_user_url(data['users'].first['id']), response.location
21 | end
22 |
23 | test 'should not create a user without a name' do
24 | post '/v1/users',
25 | { user:
26 | { name: nil, age: 33, city: "Tulsa", state: "OK" }
27 | }.to_json,
28 | { 'Accept' => Mime::JSON, 'Content-Type' => Mime::JSON.to_s }
29 |
30 | assert_response :unprocessable_entity
31 | assert_equal Mime::JSON, response.content_type
32 | end
33 |
34 | test 'should not create a user without an age' do
35 | post '/v1/users',
36 | { user:
37 | { name: "Phil", age: nil, city: "Tulsa", state: "OK" }
38 | }.to_json,
39 | { 'Accept' => Mime::JSON, 'Content-Type' => Mime::JSON.to_s }
40 |
41 | assert_response :unprocessable_entity
42 | assert_equal Mime::JSON, response.content_type
43 | end
44 |
45 | test 'should not create a user without a city' do
46 | post '/v1/users',
47 | { user:
48 | { name: "Jim", age: 33, city: nil, state: "OK" }
49 | }.to_json,
50 | { 'Accept' => Mime::JSON, 'Content-Type' => Mime::JSON.to_s }
51 |
52 | assert_response :unprocessable_entity
53 | assert_equal Mime::JSON, response.content_type
54 | end
55 |
56 | test 'should not create a user without a state' do
57 | post '/v1/users',
58 | { user:
59 | { name: "Billy", age: 33, city: "Tulsa", state: nil }
60 | }.to_json,
61 | { 'Accept' => Mime::JSON, 'Content-Type' => Mime::JSON.to_s }
62 |
63 | assert_response :unprocessable_entity
64 | assert_equal Mime::JSON, response.content_type
65 | end
66 |
67 | end
68 |
--------------------------------------------------------------------------------
/test/integration/users/deleting_users_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class DeletingUsersTest < ActionDispatch::IntegrationTest
4 |
5 | setup do
6 | host! 'api.example.com' #required for testing with a subdomain constraint
7 | @user = create(:user)
8 | end
9 |
10 | test 'should delete a user' do
11 | delete "/v1/users/#{@user.id}"
12 | assert_response :no_content
13 | end
14 |
15 | end
16 |
--------------------------------------------------------------------------------
/test/integration/users/listing_users_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class ListingUsersTest < ActionDispatch::IntegrationTest
4 | setup do
5 | host! 'api.example.com' #required for testing with a subdomain constraint
6 | @user1 = create(:user)
7 | @user2 = create(:user)
8 | end
9 |
10 | test 'should return a list of users' do
11 | get '/v1/users.json'
12 | assert_response :success
13 | refute_empty response.body
14 | end
15 |
16 | test 'should return users filtered by name' do
17 | get "/v1/users.json?name=#{@user1.name}"
18 | assert_response :success
19 |
20 | data = JSON.parse(response.body)
21 | names = data['users'].collect { |u| u['name'] }
22 | assert_includes names, @user1.name
23 | refute_includes names, @user2.name
24 | end
25 |
26 | test 'should return a user by id' do
27 | get "/v1/users/#{@user1.id}.json"
28 | assert_response :success
29 |
30 | data = JSON.parse(response.body)
31 | assert_equal @user1.name, data['users'].first['name']
32 | end
33 |
34 | test 'returns users in JSON' do
35 | get '/v1/users', {}, { accept: Mime::JSON }
36 | assert_response :success
37 | assert_equal Mime::JSON, response.content_type
38 | end
39 |
40 | test 'returns users in XML' do
41 | get '/v1/users', {}, { accept: Mime::XML }
42 | assert_response :success
43 | assert_equal Mime::XML, response.content_type
44 | end
45 |
46 | end
47 |
--------------------------------------------------------------------------------
/test/integration/users/updating_users_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class UpdatingUsersTest < ActionDispatch::IntegrationTest
4 |
5 | setup do
6 | host! 'api.example.com' #required for testing with a subdomain constraint
7 | @user = create(:user)
8 | end
9 |
10 | test 'should update a user' do
11 | patch "/v1/users/#{@user.id}",
12 | { user:
13 | { name: "Stiffmiester" }
14 | }.to_json,
15 | { 'Accept' => Mime::JSON, 'Content-Type' => Mime::JSON.to_s }
16 |
17 | assert_response :success
18 | assert_equal 'Stiffmiester', @user.reload.name
19 | end
20 |
21 | test 'should not update a user with a invalid age' do
22 | patch "/v1/users/#{@user.id}",
23 | { user:
24 | { age: 250 }
25 | }.to_json,
26 | { 'Accept' => Mime::JSON, 'Content-Type' => Mime::JSON.to_s }
27 |
28 | assert_response :unprocessable_entity
29 | end
30 |
31 | end
32 |
--------------------------------------------------------------------------------
/test/mailers/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodyStringham/rest-api/32f5767da6634a50e093bf68358de00da22d0039/test/mailers/.keep
--------------------------------------------------------------------------------
/test/models/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodyStringham/rest-api/32f5767da6634a50e093bf68358de00da22d0039/test/models/.keep
--------------------------------------------------------------------------------
/test/models/dream_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class DreamTest < ActiveSupport::TestCase
4 | # test "the truth" do
5 | # assert true
6 | # end
7 | end
8 |
--------------------------------------------------------------------------------
/test/models/user_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class UserTest < ActiveSupport::TestCase
4 | # test "the truth" do
5 | # assert true
6 | # end
7 | end
8 |
--------------------------------------------------------------------------------
/test/test_helper.rb:
--------------------------------------------------------------------------------
1 | require 'simplecov'
2 | SimpleCov.start
3 |
4 | ENV['RAILS_ENV'] ||= 'test'
5 | require File.expand_path('../../config/environment', __FILE__)
6 | require 'rails/test_help'
7 |
8 | class ActiveSupport::TestCase
9 | include FactoryGirl::Syntax::Methods
10 |
11 | # Add more helper methods to be used by all tests here...
12 | end
13 |
--------------------------------------------------------------------------------
/vendor/assets/javascripts/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodyStringham/rest-api/32f5767da6634a50e093bf68358de00da22d0039/vendor/assets/javascripts/.keep
--------------------------------------------------------------------------------
/vendor/assets/stylesheets/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CodyStringham/rest-api/32f5767da6634a50e093bf68358de00da22d0039/vendor/assets/stylesheets/.keep
--------------------------------------------------------------------------------