├── .gitignore
├── .rspec
├── .rubocop.yml
├── .travis.yml
├── Gemfile
├── Gemfile.lock
├── LICENSE
├── README.md
├── Rakefile
├── app
├── assets
│ └── config
│ │ └── manifest.js
└── initialize.rb
├── bin
├── bundle
├── rails
├── rake
├── setup
├── spring
├── update
└── yarn
├── config.ru
├── config
├── application.rb
├── boot.rb
├── cable.yml
├── database.yml
├── environment.rb
├── environments
│ ├── development.rb
│ ├── production.rb
│ └── test.rb
├── initializers
│ ├── application_controller_renderer.rb
│ ├── backtrace_silencers.rb
│ ├── filter_parameter_logging.rb
│ ├── inflections.rb
│ ├── mime_types.rb
│ └── wrap_parameters.rb
├── locales
│ └── en.yml
├── puma.rb
├── routes.rb
├── secrets.yml
└── spring.rb
├── db
├── migrate
│ ├── 20180323131037_create_posts.rb
│ ├── 20180411154150_create_users.rb
│ └── 20180418152629_create_comments.rb
├── schema.rb
└── seeds.rb
├── lib
├── jwt_service.rb
└── tasks
│ └── .keep
├── log
└── .keep
├── package.json
├── public
├── favicon.ico
└── robots.txt
├── spec
├── controllers
│ ├── authentication_controller_spec.rb
│ ├── comments_controller_spec.rb
│ ├── posts_controller_spec.rb
│ ├── user_authorizer.rb
│ └── users_controller_spec.rb
├── fixtures
│ └── files
│ │ ├── comments.json
│ │ ├── posts.json
│ │ └── users.json
├── lib
│ └── jwt_service_spec.rb
├── models
│ ├── comment_spec.rb
│ ├── post_spec.rb
│ └── user_spec.rb
├── rails_helper.rb
└── spec_helper.rb
├── tmp
└── .keep
└── vendor
└── .keep
/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore bundler config.
2 | .bundle
3 |
4 | # Ignore the default SQLite database.
5 | db/*.sqlite3
6 | db/*.sqlite3-journal
7 |
8 | # Ignore all logfiles and tempfiles.
9 | log/*
10 | tmp/*
11 | !/log/.keep
12 | !/tmp/.keep
13 |
14 | .byebug_history
15 |
--------------------------------------------------------------------------------
/.rspec:
--------------------------------------------------------------------------------
1 | --require rails_helper
2 |
--------------------------------------------------------------------------------
/.rubocop.yml:
--------------------------------------------------------------------------------
1 | AllCops:
2 | TargetRubyVersion: 2.6
3 | Exclude:
4 | - db/**
5 |
6 | inherit_mode:
7 | merge:
8 | - Exclude
9 |
10 | Layout/ParameterAlignment:
11 | EnforcedStyle: with_fixed_indentation
12 | Layout/BlockAlignment:
13 | EnforcedStyleAlignWith: start_of_line
14 | Layout/ClassStructure:
15 | Enabled: true
16 | Categories:
17 | module_inclusion:
18 | - include
19 | - prepend
20 | - extend
21 | attribute:
22 | - attr_accessor
23 | - attr_reader
24 | - attr_writer
25 | ExpectedOrder:
26 | - module_inclusion
27 | - constants
28 | - public_class_methods
29 | - initializer
30 | - attribute
31 | - public_methods
32 | - protected_methods
33 | - private_methods
34 | Layout/DefEndAlignment:
35 | AutoCorrect: true
36 | Layout/EmptyLineBetweenDefs:
37 | AllowAdjacentOneLineDefs: true
38 | Layout/EndAlignment:
39 | AutoCorrect: true
40 | Layout/FirstArrayElementIndentation:
41 | EnforcedStyle: consistent
42 | Layout/FirstHashElementIndentation:
43 | EnforcedStyle: consistent
44 | Layout/MultilineAssignmentLayout:
45 | Enabled: true
46 | EnforcedStyle: same_line
47 | Layout/MultilineMethodCallIndentation:
48 | EnforcedStyle: indented
49 | Layout/MultilineOperationIndentation:
50 | EnforcedStyle: indented
51 | Layout/SpaceBeforeBlockBraces:
52 | EnforcedStyle: no_space
53 | Layout/LineLength:
54 | Max: 120
55 |
56 | Metrics/AbcSize:
57 | Enabled: false
58 | Metrics/BlockLength:
59 | Exclude:
60 | - '**/*_spec.rb'
61 | Metrics/ClassLength:
62 | Max: 200
63 | Metrics/CyclomaticComplexity:
64 | Enabled: false
65 | Metrics/MethodLength:
66 | Max: 40
67 | Metrics/ModuleLength:
68 | Max: 200
69 | Metrics/ParameterLists:
70 | Max: 4
71 | CountKeywordArgs: false
72 | Metrics/PerceivedComplexity:
73 | Enabled: false
74 |
75 | Naming/AccessorMethodName:
76 | Enabled: false
77 | Naming/PredicateName:
78 | Enabled: false
79 |
80 | Style/BeginBlock:
81 | Enabled: false
82 | Style/BlockDelimiters:
83 | EnforcedStyle: braces_for_chaining
84 | Style/ClassCheck:
85 | EnforcedStyle: kind_of?
86 | Style/Documentation:
87 | Enabled: false
88 | Style/EmptyMethod:
89 | EnforcedStyle: expanded
90 | Style/FrozenStringLiteralComment:
91 | EnforcedStyle: never
92 | Style/GuardClause:
93 | Enabled: false
94 | Style/HashSyntax:
95 | EnforcedStyle: ruby19_no_mixed_keys
96 | Style/IfUnlessModifier:
97 | Enabled: false
98 | Style/ImplicitRuntimeError:
99 | Enabled: true
100 | Style/Lambda:
101 | EnforcedStyle: literal
102 | Style/MethodCallWithArgsParentheses:
103 | Enabled: true
104 | IgnoredMethods:
105 | - attribute
106 | - component
107 | - require
108 | - require_relative
109 | - describe
110 | - define
111 | - before
112 | - after
113 | - it
114 | - to
115 | - not_to
116 | - be
117 | - eq
118 | Style/PreferredHashMethods:
119 | EnforcedStyle: verbose
120 | Style/RedundantException:
121 | Enabled: false
122 | Style/RedundantReturn:
123 | Enabled: false
124 | Style/SingleLineMethods:
125 | Enabled: false
126 | Style/StringLiterals:
127 | EnforcedStyle: double_quotes
128 | Style/StringLiteralsInInterpolation:
129 | EnforcedStyle: double_quotes
130 | Style/SymbolArray:
131 | EnforcedStyle: brackets
132 | Style/WordArray:
133 | EnforcedStyle: brackets
134 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: ruby
2 | rvm: 2.6.3
3 |
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source("https://rubygems.org")
2 |
3 | git_source(:github) do |repo_name|
4 | repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
5 | "https://github.com/#{repo_name}.git"
6 | end
7 |
8 | gem("bcrypt", "~> 3.1.7")
9 | gem("jwt", "~> 2.1.0")
10 | gem("puma", "~> 5.3.1")
11 | gem("rails", "~> 5.2.3")
12 | gem("rubocop")
13 | gem("sqlite3")
14 |
15 | group :development, :test do
16 | gem("byebug", platforms: [:mri, :mingw, :x64_mingw])
17 | gem("rspec-rails")
18 | gem("simple_command")
19 | end
20 |
21 | group :development do
22 | gem("listen", "~> 3.2.0")
23 | gem("spring")
24 | gem("spring-watcher-listen", "~> 2.0.0")
25 | gem("web-console", "~> 3.7.0")
26 | end
27 |
28 | group :test do
29 | gem("database_cleaner")
30 | gem("rspec")
31 | gem("rspec-mocks")
32 | gem("shoulda-matchers", "~> 4.4.0")
33 | end
34 |
35 | gem("tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby])
36 |
--------------------------------------------------------------------------------
/Gemfile.lock:
--------------------------------------------------------------------------------
1 | GEM
2 | remote: https://rubygems.org/
3 | specs:
4 | actioncable (5.2.6)
5 | actionpack (= 5.2.6)
6 | nio4r (~> 2.0)
7 | websocket-driver (>= 0.6.1)
8 | actionmailer (5.2.6)
9 | actionpack (= 5.2.6)
10 | actionview (= 5.2.6)
11 | activejob (= 5.2.6)
12 | mail (~> 2.5, >= 2.5.4)
13 | rails-dom-testing (~> 2.0)
14 | actionpack (5.2.6)
15 | actionview (= 5.2.6)
16 | activesupport (= 5.2.6)
17 | rack (~> 2.0, >= 2.0.8)
18 | rack-test (>= 0.6.3)
19 | rails-dom-testing (~> 2.0)
20 | rails-html-sanitizer (~> 1.0, >= 1.0.2)
21 | actionview (5.2.6)
22 | activesupport (= 5.2.6)
23 | builder (~> 3.1)
24 | erubi (~> 1.4)
25 | rails-dom-testing (~> 2.0)
26 | rails-html-sanitizer (~> 1.0, >= 1.0.3)
27 | activejob (5.2.6)
28 | activesupport (= 5.2.6)
29 | globalid (>= 0.3.6)
30 | activemodel (5.2.6)
31 | activesupport (= 5.2.6)
32 | activerecord (5.2.6)
33 | activemodel (= 5.2.6)
34 | activesupport (= 5.2.6)
35 | arel (>= 9.0)
36 | activestorage (5.2.6)
37 | actionpack (= 5.2.6)
38 | activerecord (= 5.2.6)
39 | marcel (~> 1.0.0)
40 | activesupport (5.2.6)
41 | concurrent-ruby (~> 1.0, >= 1.0.2)
42 | i18n (>= 0.7, < 2)
43 | minitest (~> 5.1)
44 | tzinfo (~> 1.1)
45 | arel (9.0.0)
46 | ast (2.4.2)
47 | bcrypt (3.1.16)
48 | bindex (0.8.1)
49 | builder (3.2.4)
50 | byebug (11.1.3)
51 | concurrent-ruby (1.1.9)
52 | crass (1.0.6)
53 | database_cleaner (2.0.1)
54 | database_cleaner-active_record (~> 2.0.0)
55 | database_cleaner-active_record (2.0.1)
56 | activerecord (>= 5.a)
57 | database_cleaner-core (~> 2.0.0)
58 | database_cleaner-core (2.0.1)
59 | diff-lcs (1.4.4)
60 | erubi (1.10.0)
61 | ffi (1.15.3)
62 | globalid (0.4.2)
63 | activesupport (>= 4.2.0)
64 | i18n (1.8.10)
65 | concurrent-ruby (~> 1.0)
66 | jwt (2.1.0)
67 | listen (3.2.1)
68 | rb-fsevent (~> 0.10, >= 0.10.3)
69 | rb-inotify (~> 0.9, >= 0.9.10)
70 | loofah (2.10.0)
71 | crass (~> 1.0.2)
72 | nokogiri (>= 1.5.9)
73 | mail (2.7.1)
74 | mini_mime (>= 0.1.1)
75 | marcel (1.0.1)
76 | method_source (1.0.0)
77 | mini_mime (1.1.0)
78 | minitest (5.14.4)
79 | nio4r (2.5.7)
80 | nokogiri (1.11.7-x86_64-linux)
81 | racc (~> 1.4)
82 | parallel (1.20.1)
83 | parser (3.0.2.0)
84 | ast (~> 2.4.1)
85 | puma (5.3.1)
86 | nio4r (~> 2.0)
87 | racc (1.5.2)
88 | rack (2.2.3)
89 | rack-test (1.1.0)
90 | rack (>= 1.0, < 3)
91 | rails (5.2.6)
92 | actioncable (= 5.2.6)
93 | actionmailer (= 5.2.6)
94 | actionpack (= 5.2.6)
95 | actionview (= 5.2.6)
96 | activejob (= 5.2.6)
97 | activemodel (= 5.2.6)
98 | activerecord (= 5.2.6)
99 | activestorage (= 5.2.6)
100 | activesupport (= 5.2.6)
101 | bundler (>= 1.3.0)
102 | railties (= 5.2.6)
103 | sprockets-rails (>= 2.0.0)
104 | rails-dom-testing (2.0.3)
105 | activesupport (>= 4.2.0)
106 | nokogiri (>= 1.6)
107 | rails-html-sanitizer (1.3.0)
108 | loofah (~> 2.3)
109 | railties (5.2.6)
110 | actionpack (= 5.2.6)
111 | activesupport (= 5.2.6)
112 | method_source
113 | rake (>= 0.8.7)
114 | thor (>= 0.19.0, < 2.0)
115 | rainbow (3.0.0)
116 | rake (13.0.6)
117 | rb-fsevent (0.11.0)
118 | rb-inotify (0.10.1)
119 | ffi (~> 1.0)
120 | regexp_parser (2.1.1)
121 | rexml (3.2.5)
122 | rspec (3.10.0)
123 | rspec-core (~> 3.10.0)
124 | rspec-expectations (~> 3.10.0)
125 | rspec-mocks (~> 3.10.0)
126 | rspec-core (3.10.1)
127 | rspec-support (~> 3.10.0)
128 | rspec-expectations (3.10.1)
129 | diff-lcs (>= 1.2.0, < 2.0)
130 | rspec-support (~> 3.10.0)
131 | rspec-mocks (3.10.2)
132 | diff-lcs (>= 1.2.0, < 2.0)
133 | rspec-support (~> 3.10.0)
134 | rspec-rails (5.0.1)
135 | actionpack (>= 5.2)
136 | activesupport (>= 5.2)
137 | railties (>= 5.2)
138 | rspec-core (~> 3.10)
139 | rspec-expectations (~> 3.10)
140 | rspec-mocks (~> 3.10)
141 | rspec-support (~> 3.10)
142 | rspec-support (3.10.2)
143 | rubocop (1.18.3)
144 | parallel (~> 1.10)
145 | parser (>= 3.0.0.0)
146 | rainbow (>= 2.2.2, < 4.0)
147 | regexp_parser (>= 1.8, < 3.0)
148 | rexml
149 | rubocop-ast (>= 1.7.0, < 2.0)
150 | ruby-progressbar (~> 1.7)
151 | unicode-display_width (>= 1.4.0, < 3.0)
152 | rubocop-ast (1.8.0)
153 | parser (>= 3.0.1.1)
154 | ruby-progressbar (1.11.0)
155 | shoulda-matchers (4.4.1)
156 | activesupport (>= 4.2.0)
157 | simple_command (0.1.0)
158 | spring (2.1.1)
159 | spring-watcher-listen (2.0.1)
160 | listen (>= 2.7, < 4.0)
161 | spring (>= 1.2, < 3.0)
162 | sprockets (4.0.2)
163 | concurrent-ruby (~> 1.0)
164 | rack (> 1, < 3)
165 | sprockets-rails (3.2.2)
166 | actionpack (>= 4.0)
167 | activesupport (>= 4.0)
168 | sprockets (>= 3.0.0)
169 | sqlite3 (1.4.2)
170 | thor (1.1.0)
171 | thread_safe (0.3.6)
172 | tzinfo (1.2.9)
173 | thread_safe (~> 0.1)
174 | unicode-display_width (2.0.0)
175 | web-console (3.7.0)
176 | actionview (>= 5.0)
177 | activemodel (>= 5.0)
178 | bindex (>= 0.4.0)
179 | railties (>= 5.0)
180 | websocket-driver (0.7.5)
181 | websocket-extensions (>= 0.1.0)
182 | websocket-extensions (0.1.5)
183 |
184 | PLATFORMS
185 | x86_64-linux
186 |
187 | DEPENDENCIES
188 | bcrypt (~> 3.1.7)
189 | byebug
190 | database_cleaner
191 | jwt (~> 2.1.0)
192 | listen (~> 3.2.0)
193 | puma (~> 5.3.1)
194 | rails (~> 5.2.3)
195 | rspec
196 | rspec-mocks
197 | rspec-rails
198 | rubocop
199 | shoulda-matchers (~> 4.4.0)
200 | simple_command
201 | spring
202 | spring-watcher-listen (~> 2.0.0)
203 | sqlite3
204 | tzinfo-data
205 | web-console (~> 3.7.0)
206 |
207 | BUNDLED WITH
208 | 2.2.15
209 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://travis-ci.org/YuKitAs/rails-rest-api)
2 |
3 | # Rails Rest API
4 |
5 | ## Project Setup
6 |
7 | **Install all gems**:
8 |
9 | ```console
10 | $ bundle install
11 | ```
12 |
13 | **Update the database with new data model**:
14 |
15 | ```console
16 | $ rake db:migrate
17 | ```
18 |
19 | **Feed the database with default seeds**:
20 |
21 | ```console
22 | $ rake db:seed
23 | ```
24 |
25 | **Start the web server on `http://localhost:3000` by default**:
26 |
27 | ```console
28 | $ rails server
29 | ```
30 |
31 | **Run all RSpec tests and Rubocop**:
32 |
33 | ```console
34 | $ rake test
35 | ```
36 |
37 | ## Usage
38 |
39 | | HTTP verbs | Paths | Used for |
40 | | ---------- | ------ | --------:|
41 | | POST | /register| Create a user|
42 | | POST | /login | Authenticate a user |
43 | | GET | /posts | List all posts|
44 | | GET | /posts/:post_id | Show a single post |
45 | | POST | /posts | Create a post |
46 | | PUT | /posts/:post_id | Update a post |
47 | | DELETE | /posts/:post_id | Delete a post |
48 | | GET | /posts/:post_id/comments | List all comments of a post |
49 | | GET | /posts/:post_id/comments/:comment_id | Show a single comment |
50 | | POST | /posts/:post_id/comments | Create a comment |
51 | | PUT | /posts/:post_id/comments/:comment_id | Update a comment |
52 | | DELETE | /posts/:post_id/comments/:comment_id | Delete a comment |
53 |
54 | ## Use Case Examples
55 |
56 | ### Authentication
57 |
58 | **Create a new user**:
59 |
60 | ```console
61 | $ curl -X POST -H 'Content-type: application/json' -d '{"email": "testuser@email.com", "password": "testuser123"}' localhost:3000/register
62 | ```
63 |
64 | **Authenticate a user**:
65 |
66 | ```console
67 | $ curl -X POST -H 'Content-type: application/json' -d '{"email": "testuser@email.com", "password": "testuser123"}' localhost:3000/login
68 | ```
69 |
70 | On successful login, `{"auth_token": }` will be returned. This token will be expired after 24 hours.
71 |
72 | ### CRUD
73 |
74 | **In order to access the posts and comments, add `-H 'Authorization: '` to the header of every request for CRUD operations.**
75 |
76 | The `create`, `update` and `delete` actions can only be executed by users authorized on admin. A default admin user is definded in `db/seeds.rb`. After seeding the database, `{"email": "admin@email.com", "password": "admin123"}` can be used to login as an admin.
77 |
78 | **Create a new post**:
79 |
80 | ```console
81 | $ curl -X POST -H 'Content-type: application/json' -d '{"title": "My title", "content": "My content"}' localhost:3000/posts
82 | ```
83 |
84 | **Create a new comment**:
85 |
86 | ```console
87 | $ curl -X POST -H 'Content-type: application/json' -d '{"name": "YuKitAs", "message": "My message"}' localhost:3000/posts/1/comments
88 | ```
89 |
90 | The `name` field is optional with default value `anonym`.
91 |
92 | **Update an existing post by id**:
93 |
94 | ```console
95 | $ curl -X PUT -H 'Content-type: application/json' -d '{"title": "My new title", "content": "My new content"}' localhost:3000/posts/1
96 | ```
97 |
98 | **Update an existing comment by id**:
99 |
100 | ```console
101 | $ curl -X PUT -H 'Content-type: application/json' -d '{"name": "YuKitAs", "message": "My new message"}' localhost:3000/posts/2/comments/1
102 | ```
103 |
104 | **Delete an existing post by id**:
105 |
106 | ```console
107 | $ curl -X DELETE localhost:3000/posts/1
108 | ```
109 |
110 | All the comments of this post will be deleted as well.
111 |
112 | **Delete an existing comment by id**:
113 |
114 | ```console
115 | $ curl -X DELETE localhost:3000/posts/2/comments/1
116 | ```
117 |
--------------------------------------------------------------------------------
/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_relative "config/application"
5 |
6 | Rails.application.load_tasks
7 |
8 | task(default: [:test])
9 |
10 | task :test do
11 | sh "rspec spec"
12 | sh "rubocop"
13 | end
14 |
--------------------------------------------------------------------------------
/app/assets/config/manifest.js:
--------------------------------------------------------------------------------
1 | {}
2 |
--------------------------------------------------------------------------------
/app/initialize.rb:
--------------------------------------------------------------------------------
1 | $LOAD_PATH.unshift(__dir__) unless $LOAD_PATH.include?(__dir__)
2 |
--------------------------------------------------------------------------------
/bin/bundle:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
3 | load(Gem.bin_path("bundler", "bundle"))
4 |
--------------------------------------------------------------------------------
/bin/rails:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | begin
3 | load(File.expand_path("spring", __dir__))
4 | rescue LoadError => e
5 | raise unless e.message.include?("spring")
6 | end
7 | APP_PATH = File.expand_path("../config/application", __dir__)
8 | require_relative "../config/boot"
9 | require "rails/commands"
10 |
--------------------------------------------------------------------------------
/bin/rake:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | begin
3 | load(File.expand_path("spring", __dir__))
4 | rescue LoadError => e
5 | raise unless e.message.include?("spring")
6 | end
7 | require_relative "../config/boot"
8 | require "rake"
9 | Rake.application.run
10 |
--------------------------------------------------------------------------------
/bin/setup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require "pathname"
3 | require "fileutils"
4 | # rubocop:disable Style/MixinUsage
5 | include(FileUtils)
6 | # rubocop:enable Style/MixinUsage
7 |
8 | # path to your application root.
9 | APP_ROOT = Pathname.new(File.expand_path("..", __dir__))
10 |
11 | def system!(*args)
12 | system(*args) || abort("\n== Command #{args} failed ==")
13 | end
14 |
15 | chdir APP_ROOT do
16 | # This script is a starting point to setup your application.
17 | # Add necessary setup steps to this file.
18 |
19 | puts "== Installing dependencies =="
20 | system! "gem install bundler --conservative"
21 | system("bundle check") || system!("bundle install")
22 |
23 | # Install JavaScript dependencies if using Yarn
24 | # system('bin/yarn')
25 |
26 | # puts "\n== Copying sample files =="
27 | # unless File.exist?('config/database.yml')
28 | # cp 'config/database.yml.sample', 'config/database.yml'
29 | # end
30 |
31 | puts "\n== Preparing database =="
32 | system! "bin/rails db:setup"
33 |
34 | puts "\n== Removing old logs and tempfiles =="
35 | system! "bin/rails log:clear tmp:clear"
36 |
37 | puts "\n== Restarting application server =="
38 | system! "bin/rails restart"
39 | end
40 |
--------------------------------------------------------------------------------
/bin/spring:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | # This file loads spring without using Bundler, in order to be fast.
4 | # It gets overwritten when you run the `spring binstub` command.
5 |
6 | unless defined?(Spring)
7 | require "rubygems"
8 | require "bundler"
9 |
10 | lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
11 | spring = lockfile.specs.detect{ |spec| spec.name == "spring" }
12 | if spring
13 | Gem.use_paths(Gem.dir, Bundler.bundle_path.to_s, *Gem.path)
14 | gem("spring", spring.version)
15 | require "spring/binstub"
16 | end
17 | end
18 |
--------------------------------------------------------------------------------
/bin/update:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require "pathname"
3 | require "fileutils"
4 | # rubocop:disable Style/MixinUsage
5 | include(FileUtils)
6 | # rubocop:enable Style/MixinUsage
7 |
8 | # path to your application root.
9 | APP_ROOT = Pathname.new(File.expand_path("..", __dir__))
10 |
11 | def system!(*args)
12 | system(*args) || abort("\n== Command #{args} failed ==")
13 | end
14 |
15 | chdir APP_ROOT do
16 | # This script is a way to update your development environment automatically.
17 | # Add necessary update steps to this file.
18 |
19 | puts "== Installing dependencies =="
20 | system! "gem install bundler --conservative"
21 | system("bundle check") || system!("bundle install")
22 |
23 | puts "\n== Updating database =="
24 | system! "bin/rails db:migrate"
25 |
26 | puts "\n== Removing old logs and tempfiles =="
27 | system! "bin/rails log:clear tmp:clear"
28 |
29 | puts "\n== Restarting application server =="
30 | system! "bin/rails restart"
31 | end
32 |
--------------------------------------------------------------------------------
/bin/yarn:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | VENDOR_PATH = File.expand_path("..", __dir__)
3 | # rubocop:disable Style/RedundantBegin
4 | Dir.chdir(VENDOR_PATH) do
5 | begin
6 | exec("yarnpkg #{ARGV.join(" ")}")
7 | rescue Errno::ENOENT
8 | warn("Yarn executable was not detected in the system.")
9 | warn("Download Yarn at https://yarnpkg.com/en/docs/install")
10 | exit(1)
11 | end
12 | end
13 | # rubocop:enable Style/RedundantBegin
14 |
--------------------------------------------------------------------------------
/config.ru:
--------------------------------------------------------------------------------
1 | # This file is used by Rack-based servers to start the application.
2 |
3 | require_relative "config/environment"
4 |
5 | run(Rails.application)
6 |
--------------------------------------------------------------------------------
/config/application.rb:
--------------------------------------------------------------------------------
1 | require_relative "boot"
2 |
3 | require "rails"
4 | # Pick the frameworks you want:
5 | require "active_model/railtie"
6 | require "active_job/railtie"
7 | require "active_record/railtie"
8 | require "action_controller/railtie"
9 | require "action_mailer/railtie"
10 | require "action_view/railtie"
11 | require "action_cable/engine"
12 | require "sprockets/railtie"
13 | # require "rails/test_unit/railtie"
14 |
15 |
16 | Bundler.require(*Rails.groups)
17 |
18 | module RailsRestApi
19 | class Application < Rails::Application
20 | # Initialize configuration defaults for originally generated Rails version.
21 | config.load_defaults(5.1)
22 |
23 | # Settings in config/environments/* take precedence over those specified here.
24 | # Application configuration should go into files in config/initializers
25 | # -- all .rb files in that directory are automatically loaded.
26 |
27 | # Don't generate system test files.
28 | config.api_only = true
29 |
30 | config.autoload_paths << Rails.root.join("lib")
31 | end
32 | end
33 |
--------------------------------------------------------------------------------
/config/boot.rb:
--------------------------------------------------------------------------------
1 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
2 |
3 | require "bundler/setup" # Set up gems listed in the Gemfile.
4 |
--------------------------------------------------------------------------------
/config/cable.yml:
--------------------------------------------------------------------------------
1 | development:
2 | adapter: async
3 |
4 | test:
5 | adapter: async
6 |
7 | production:
8 | adapter: redis
9 | url: redis://localhost:6379/1
10 | channel_prefix: rails-rest-api_production
11 |
--------------------------------------------------------------------------------
/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 | #
7 | default: &default
8 | adapter: sqlite3
9 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
10 | timeout: 5000
11 |
12 | development:
13 | <<: *default
14 | database: db/development.sqlite3
15 |
16 | # Warning: The database defined as "test" will be erased and
17 | # re-generated from your development database when you run "rake".
18 | # Do not set this db to the same as development or production.
19 | test:
20 | <<: *default
21 | database: db/test.sqlite3
22 |
23 | production:
24 | <<: *default
25 | database: db/production.sqlite3
26 |
--------------------------------------------------------------------------------
/config/environment.rb:
--------------------------------------------------------------------------------
1 | # Load the Rails application.
2 | require_relative "application"
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.
13 | config.consider_all_requests_local = true
14 |
15 | # Enable/disable caching. By default caching is disabled.
16 | if Rails.root.join("tmp/caching-dev.txt").exist?
17 | config.action_controller.perform_caching = true
18 |
19 | config.cache_store = :memory_store
20 | config.public_file_server.headers = {
21 | "Cache-Control" => "public, max-age=#{2.days.seconds.to_i}"
22 | }
23 | else
24 | config.action_controller.perform_caching = false
25 |
26 | config.cache_store = :null_store
27 | end
28 |
29 | # Don't care if the mailer can't send.
30 | config.action_mailer.raise_delivery_errors = false
31 |
32 | config.action_mailer.perform_caching = false
33 |
34 | # Print deprecation notices to the Rails logger.
35 | config.active_support.deprecation = :log
36 |
37 | # Raise an error on page load if there are pending migrations.
38 | config.active_record.migration_error = :page_load
39 |
40 | # Raises error for missing translations
41 | # config.action_view.raise_on_missing_translations = true
42 |
43 | # Use an evented file watcher to asynchronously detect changes in source code,
44 | # routes, locales, etc. This feature depends on the listen gem.
45 | config.file_watcher = ActiveSupport::EventedFileUpdateChecker
46 | end
47 |
--------------------------------------------------------------------------------
/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 | # Attempt to read encrypted secrets from `config/secrets.yml.enc`.
18 | # Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or
19 | # `config/secrets.yml.key`.
20 | config.read_encrypted_secrets = true
21 |
22 | # Disable serving static files from the `/public` folder by default since
23 | # Apache or NGINX already handles this.
24 | config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?
25 |
26 | # Enable serving of images, stylesheets, and JavaScripts from an asset server.
27 | # config.action_controller.asset_host = 'http://assets.example.com'
28 |
29 | # Specifies the header that your server uses for sending files.
30 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
31 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
32 |
33 | # Mount Action Cable outside main process or domain
34 | # config.action_cable.mount_path = nil
35 | # config.action_cable.url = 'wss://example.com/cable'
36 | # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
37 |
38 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
39 | # config.force_ssl = true
40 |
41 | # Use the lowest log level to ensure availability of diagnostic information
42 | # when problems arise.
43 | config.log_level = :debug
44 |
45 | # Prepend all log lines with the following tags.
46 | config.log_tags = [:request_id]
47 |
48 | # Use a different cache store in production.
49 | # config.cache_store = :mem_cache_store
50 |
51 | # Use a real queuing backend for Active Job (and separate queues per environment)
52 | # config.active_job.queue_adapter = :resque
53 | # config.active_job.queue_name_prefix = "rails-rest-api_#{Rails.env}"
54 | config.action_mailer.perform_caching = false
55 |
56 | # Ignore bad email addresses and do not raise email delivery errors.
57 | # Set this to true and configure the email server for immediate delivery to raise delivery errors.
58 | # config.action_mailer.raise_delivery_errors = false
59 |
60 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
61 | # the I18n.default_locale when a translation cannot be found).
62 | config.i18n.fallbacks = true
63 |
64 | # Send deprecation notices to registered listeners.
65 | config.active_support.deprecation = :notify
66 |
67 | # Use default logging formatter so that PID and timestamp are not suppressed.
68 | config.log_formatter = ::Logger::Formatter.new
69 |
70 | # Use a different logger for distributed setups.
71 | # require 'syslog/logger'
72 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
73 |
74 | if ENV["RAILS_LOG_TO_STDOUT"].present?
75 | logger = ActiveSupport::Logger.new($stdout)
76 | logger.formatter = config.log_formatter
77 | config.logger = ActiveSupport::TaggedLogging.new(logger)
78 | end
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 public file server for tests with Cache-Control for performance.
16 | config.public_file_server.enabled = true
17 | config.public_file_server.headers = {
18 | "Cache-Control" => "public, max-age=#{1.hour.seconds.to_i}"
19 | }
20 |
21 | # Show full error reports and disable caching.
22 | config.consider_all_requests_local = true
23 | config.action_controller.perform_caching = false
24 |
25 | # Raise exceptions instead of rendering exception templates.
26 | config.action_dispatch.show_exceptions = false
27 |
28 | # Disable request forgery protection in test environment.
29 | config.action_controller.allow_forgery_protection = false
30 | config.action_mailer.perform_caching = false
31 |
32 | # Tell Action Mailer not to deliver emails to the real world.
33 | # The :test delivery method accumulates sent emails in the
34 | # ActionMailer::Base.deliveries array.
35 | config.action_mailer.delivery_method = :test
36 |
37 | # Print deprecation notices to the stderr.
38 | config.active_support.deprecation = :stderr
39 |
40 | # Raises error for missing translations
41 | # config.action_view.raise_on_missing_translations = true
42 | end
43 |
--------------------------------------------------------------------------------
/config/initializers/application_controller_renderer.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # ActiveSupport::Reloader.to_prepare do
4 | # ApplicationController.renderer.defaults.merge!(
5 | # http_host: 'example.org',
6 | # https: false
7 | # )
8 | # end
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/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/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]
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 | # The following keys must be escaped otherwise they will not be retrieved by
20 | # the default I18n backend:
21 | #
22 | # true, false, on, off, yes, no
23 | #
24 | # Instead, surround them with single quotes.
25 | #
26 | # en:
27 | # 'true': 'foo'
28 | #
29 | # To learn more, please read the Rails Internationalization guide
30 | # available at http://guides.rubyonrails.org/i18n.html.
31 |
32 | en:
33 | hello: "Hello world"
34 |
--------------------------------------------------------------------------------
/config/puma.rb:
--------------------------------------------------------------------------------
1 | # Puma can serve each request in a thread from an internal thread pool.
2 | # The `threads` method setting takes two numbers: a minimum and maximum.
3 | # Any libraries that use thread pools should be configured to match
4 | # the maximum value specified for Puma. Default is set to 5 threads for minimum
5 | # and maximum; this matches the default thread size of Active Record.
6 | #
7 | threads_count = ENV.fetch("RAILS_MAX_THREADS", 5)
8 | threads(threads_count, threads_count)
9 |
10 | # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
11 | #
12 | port(ENV.fetch("PORT", 3000))
13 |
14 | # Specifies the `environment` that Puma will run in.
15 | #
16 | environment(ENV.fetch("RAILS_ENV"){ "development" })
17 |
18 | # Specifies the number of `workers` to boot in clustered mode.
19 | # Workers are forked webserver processes. If using threads and workers together
20 | # the concurrency of the application would be max `threads` * `workers`.
21 | # Workers do not work on JRuby or Windows (both of which do not support
22 | # processes).
23 | #
24 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 }
25 |
26 | # Use the `preload_app!` method when specifying a `workers` number.
27 | # This directive tells Puma to first boot the application and load code
28 | # before forking the application. This takes advantage of Copy On Write
29 | # process behavior so workers use less memory. If you use this option
30 | # you need to make sure to reconnect any threads in the `on_worker_boot`
31 | # block.
32 | #
33 | # preload_app!
34 |
35 | # If you are preloading your application and using Active Record, it's
36 | # recommended that you close any connections to the database before workers
37 | # are forked to prevent connection leakage.
38 | #
39 | # before_fork do
40 | # ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
41 | # end
42 |
43 | # The code in the `on_worker_boot` will be called if you are using
44 | # clustered mode by specifying a number of `workers`. After each worker
45 | # process is booted, this block will be run. If you are using the `preload_app!`
46 | # option, you will want to use this block to reconnect to any threads
47 | # or connections that may have been created at application boot, as Ruby
48 | # cannot share connections between processes.
49 | #
50 | # on_worker_boot do
51 | # ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
52 | # end
53 | #
54 |
55 | # Allow puma to be restarted by `rails restart` command.
56 | plugin(:tmp_restart)
57 |
--------------------------------------------------------------------------------
/config/routes.rb:
--------------------------------------------------------------------------------
1 | Rails.application.routes.draw do
2 | resources :posts do
3 | resources :comments
4 | end
5 |
6 | post "register" => "users#register"
7 | post "login" => "authentication#login"
8 | end
9 |
--------------------------------------------------------------------------------
/config/secrets.yml:
--------------------------------------------------------------------------------
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 `rails secret` to generate a secure secret key.
9 |
10 | # Make sure the secrets in this file are kept private
11 | # if you're sharing your code publicly.
12 |
13 | # Shared secrets are available across all environments.
14 |
15 | # shared:
16 | # api_key: a1B2c3D4e5F6
17 |
18 | # Environmental secrets are only available for that specific environment.
19 |
20 | development:
21 | secret_key_base: f149cbe357ad37c3a6163621fa62563f4d892b790f673efc52583e11537d6f3110de25be9341c758686b929a307fcc8104a20f8dce13b74c58f572bcd0168e9a
22 |
23 | test:
24 | secret_key_base: 4b30c2f3d594b091f9a49db9ef89191773e332a9e877264629b38e297d791801ff292889c2c220ec82369fab253602a059473f1cd2b0ac84b59b365a966b9bb3
25 |
26 | # Do not keep production secrets in the unencrypted secrets file.
27 | # Instead, either read values from the environment.
28 | # Or, use `bin/rails secrets:setup` to configure encrypted secrets
29 | # and move the `production:` environment over there.
30 |
31 | production:
32 | secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
33 |
--------------------------------------------------------------------------------
/config/spring.rb:
--------------------------------------------------------------------------------
1 | [".ruby-version", ".rbenv-vars", "tmp/restart.txt", "tmp/caching-dev.txt"].each{ |path| Spring.watch(path) }
2 |
--------------------------------------------------------------------------------
/db/migrate/20180323131037_create_posts.rb:
--------------------------------------------------------------------------------
1 | class CreatePosts < ActiveRecord::Migration[5.1]
2 | def change
3 | create_table(:posts) do |t|
4 | t.text(:title)
5 | t.text(:content)
6 |
7 | t.timestamps
8 | end
9 | end
10 | end
11 |
--------------------------------------------------------------------------------
/db/migrate/20180411154150_create_users.rb:
--------------------------------------------------------------------------------
1 | class CreateUsers < ActiveRecord::Migration[5.1]
2 | def change
3 | create_table(:users) do |t|
4 | t.string(:email, null: false)
5 | t.string(:password_digest, null: false)
6 | t.boolean(:admin, default: false)
7 |
8 | t.timestamps
9 | end
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/db/migrate/20180418152629_create_comments.rb:
--------------------------------------------------------------------------------
1 | class CreateComments < ActiveRecord::Migration[5.1]
2 | def change
3 | create_table(:comments) do |t|
4 | t.string(:name, default: "anonym")
5 | t.string(:message)
6 | t.references(:post, foreign_key: true)
7 |
8 | t.timestamps
9 | end
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/db/schema.rb:
--------------------------------------------------------------------------------
1 | # This file is auto-generated from the current state of the database. Instead
2 | # of editing this file, please use the migrations feature of Active Record to
3 | # incrementally modify your database, and then regenerate this schema definition.
4 | #
5 | # Note that this schema.rb definition is the authoritative source for your
6 | # database schema. If you need to create the application database on another
7 | # system, you should be using db:schema:load, not running all the migrations
8 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9 | # you'll amass, the slower it'll run and the greater likelihood for issues).
10 | #
11 | # It's strongly recommended that you check this file into your version control system.
12 |
13 | ActiveRecord::Schema.define(version: 2018_04_18_152629) do
14 |
15 | create_table "comments", force: :cascade do |t|
16 | t.string "name", default: "anonym"
17 | t.string "message"
18 | t.integer "post_id"
19 | t.datetime "created_at", null: false
20 | t.datetime "updated_at", null: false
21 | t.index ["post_id"], name: "index_comments_on_post_id"
22 | end
23 |
24 | create_table "posts", force: :cascade do |t|
25 | t.text "title"
26 | t.text "content"
27 | t.datetime "created_at", null: false
28 | t.datetime "updated_at", null: false
29 | end
30 |
31 | create_table "users", force: :cascade do |t|
32 | t.string "email", null: false
33 | t.string "password_digest", null: false
34 | t.boolean "admin", default: false
35 | t.datetime "created_at", null: false
36 | t.datetime "updated_at", null: false
37 | end
38 |
39 | end
40 |
--------------------------------------------------------------------------------
/db/seeds.rb:
--------------------------------------------------------------------------------
1 | Post.create([
2 | {
3 | title: "Hello",
4 | content: "Hello world!"
5 | },
6 | {
7 | title: "Goodbye",
8 | content: "Goodbye world!"
9 | }
10 | ])
11 |
12 | User.create([
13 | email: "admin@email.com",
14 | password: "admin123",
15 | admin: true
16 | ])
17 |
--------------------------------------------------------------------------------
/lib/jwt_service.rb:
--------------------------------------------------------------------------------
1 | class JwtService
2 | class << self
3 | def encode(payload, exp = 24.hours.from_now)
4 | payload[:exp] = exp.to_i
5 | JWT.encode(payload, Rails.application.secrets.secret_key_base)
6 | end
7 |
8 | def decode(token)
9 | body = JWT.decode(token, Rails.application.secrets.secret_key_base)[0]
10 | HashWithIndifferentAccess.new(body)
11 | rescue JWT::DecodeError, JWT::ExpiredSignature
12 | return nil
13 | end
14 | end
15 | end
16 |
--------------------------------------------------------------------------------
/lib/tasks/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darkhorse34/rails-rest-api/c6aae062db8b5c85f3a9833168e5a3eb644fdc5f/lib/tasks/.keep
--------------------------------------------------------------------------------
/log/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darkhorse34/rails-rest-api/c6aae062db8b5c85f3a9833168e5a3eb644fdc5f/log/.keep
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "rails-rest-api",
3 | "private": true,
4 | "dependencies": {}
5 | }
6 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darkhorse34/rails-rest-api/c6aae062db8b5c85f3a9833168e5a3eb644fdc5f/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 |
--------------------------------------------------------------------------------
/spec/controllers/authentication_controller_spec.rb:
--------------------------------------------------------------------------------
1 | RSpec.describe AuthenticationController, type: :controller do
2 | before :each do
3 | @test_user = JSON.parse(file_fixture("users.json").read)["testUser"]
4 | User.create!(@test_user)
5 | end
6 |
7 | describe "POST #login" do
8 | context "with correct credentials" do
9 | it "logs in a registered user" do
10 | post :login, params: @test_user
11 |
12 | expect(response.message).to eq "OK"
13 | expect(response.body).to include("auth_token")
14 | end
15 | end
16 |
17 | context "with incorrect credentials" do
18 | it "returns error Unauthorized" do
19 | post :login, params: { email: @test_user["email"], password: "falsepassword" }
20 |
21 | expect(response.message).to eq "Unauthorized"
22 | end
23 |
24 | it "returns error Not Found" do
25 | post :login, params: { email: "nouser@email.com", password: "nopassword" }
26 |
27 | expect(response.message).to eq "Not Found"
28 | end
29 | end
30 | end
31 | end
32 |
--------------------------------------------------------------------------------
/spec/controllers/comments_controller_spec.rb:
--------------------------------------------------------------------------------
1 | require_relative "user_authorizer"
2 |
3 | RSpec.describe CommentsController, type: "controller" do
4 | before :each do
5 | comments = JSON.parse(file_fixture("comments.json").read)
6 | @comment = comments["comment"]
7 | @new_comment = comments["newComment"]
8 |
9 | @post_id = Post.create!(JSON.parse(file_fixture("posts.json").read)["post"]).to_param
10 | @post_comments = Post.find(@post_id).comments
11 | @post_comments.create!(@comment)
12 |
13 | @comment_id = @post_comments.first.id
14 | @new_comment_params = @new_comment.merge(post_id: @post_id)
15 | end
16 |
17 | describe "GET #index" do
18 | it "lists all comments of a post" do
19 | login(:user)
20 | Post.find(@post_id).comments.create!(@new_comment)
21 | get :index, params: { post_id: @post_id }
22 |
23 | expect(response).to be_success
24 | expect(JSON.parse(response.body).size).to be 2
25 | end
26 | end
27 |
28 | describe "GET #show" do
29 | it "shows a single comment by id of a post" do
30 | login(:user)
31 | get :show, params: { post_id: @post_id, id: @comment_id }
32 | body = JSON.parse(response.body)
33 |
34 | expect(response).to be_success
35 | expect(body["name"]).to eq @comment["name"]
36 | expect(body["message"]).to eq @comment["message"]
37 | end
38 | end
39 |
40 | describe "POST #create" do
41 | context "with admin rights" do
42 | it "creates a new comment" do
43 | expect(@post_comments.find_by(name: @new_comment["name"])).to be_nil
44 |
45 | login(:admin)
46 | post :create, params: @new_comment_params
47 |
48 | expect(@post_comments.find_by(name: @new_comment["name"]).message).to eq @new_comment["message"]
49 | end
50 | end
51 |
52 | context "without admin rights" do
53 | it "does not create comment" do
54 | login(:user)
55 | post :create, params: @new_comment_params
56 |
57 | expect(response.message).to eq "Forbidden"
58 | expect(@post_comments.find_by(name: @new_comment["name"])).to be_nil
59 | end
60 | end
61 | end
62 |
63 | describe "PUT #update" do
64 | context "with admin rights" do
65 | it "updates an existing comment by id" do
66 | expect(@post_comments.find_by(name: @comment["name"]).message).to eq @comment["message"]
67 |
68 | login(:admin)
69 | put :update, params: @new_comment_params.merge(id: @comment_id)
70 |
71 | expect(@post_comments.find_by(name: @comment["name"])).to be_nil
72 | expect(@post_comments.find(@comment_id).name).to eq @new_comment["name"]
73 | expect(@post_comments.find(@comment_id).message).to eq @new_comment["message"]
74 | end
75 | end
76 |
77 | context "without admin rights" do
78 | it "does not update comment" do
79 | login(:user)
80 | put :update, params: @new_comment_params.merge(id: @comment_id)
81 |
82 | expect(response.message).to eq "Forbidden"
83 | expect(@post_comments.find_by(name: @comment["name"]).message).to eq @comment["message"]
84 | expect(@post_comments.find_by(name: @new_comment["name"])).to be_nil
85 | end
86 | end
87 | end
88 |
89 | describe "DELETE #destroy" do
90 | context "with admin rights" do
91 | it "deletes an existing comment by id of a post" do
92 | login(:admin)
93 | delete :destroy, params: { post_id: @post_id, id: @comment_id }
94 |
95 | expect(@post_comments.find_by(name: @comment["name"])).to be_nil
96 | end
97 | end
98 |
99 | context "without admin rights" do
100 | it "does not delete comment" do
101 | login(:user)
102 | delete :destroy, params: { post_id: @post_id, id: @comment_id }
103 |
104 | expect(response.message).to eq "Forbidden"
105 | expect(@post_comments.find(@comment_id)).to be_truthy
106 | end
107 | end
108 | end
109 | end
110 |
111 | private
112 |
113 | def login(access_level)
114 | allow(AuthorizeApiRequest).to receive_message_chain(:call, :result){ UserAuthorizer.current_user(access_level) }
115 | end
116 |
--------------------------------------------------------------------------------
/spec/controllers/posts_controller_spec.rb:
--------------------------------------------------------------------------------
1 | require_relative "user_authorizer"
2 |
3 | RSpec.describe PostsController, type: "controller" do
4 | before :each do
5 | posts = JSON.parse(file_fixture("posts.json").read)
6 | @post = posts["post"]
7 | @new_post = posts["newPost"]
8 | @post_id = Post.create!(@post).to_param
9 | end
10 |
11 | describe "GET #index" do
12 | it "lists all posts" do
13 | login(:user)
14 | Post.create!(@new_post)
15 | get :index
16 |
17 | expect(response).to be_success
18 | expect(JSON.parse(response.body).size).to be 2
19 | end
20 | end
21 |
22 | describe "GET #show" do
23 | it "shows a single post by id" do
24 | login(:user)
25 | get :show, params: { id: @post_id }
26 | body = JSON.parse(response.body)
27 |
28 | expect(response).to be_success
29 | expect(body["title"]).to eq @post["title"]
30 | expect(body["content"]).to eq @post["content"]
31 | end
32 | end
33 |
34 | describe "POST #create" do
35 | context "with admin rights" do
36 | it "creates a new post" do
37 | expect(Post.find_by(title: @new_post["title"])).to be_nil
38 |
39 | login(:admin)
40 | post :create, params: @new_post
41 |
42 | expect(Post.find_by(title: @new_post["title"]).content).to eq @new_post["content"]
43 | end
44 | end
45 |
46 | context "without admin rights" do
47 | it "does not create post" do
48 | login(:user)
49 | post :create, params: @new_post
50 |
51 | expect(response.message).to eq "Forbidden"
52 | expect(Post.find_by(title: @new_post["title"])).to be_nil
53 | end
54 | end
55 | end
56 |
57 | describe "PUT #update" do
58 | context "with admin rights" do
59 | it "updates an existing post by id" do
60 | expect(Post.find_by(title: @post["title"]).content).to eq @post["content"]
61 |
62 | login(:admin)
63 | put :update, params: { id: @post_id, post: @new_post }
64 |
65 | expect(Post.find_by(title: @post["title"])).to be_nil
66 | expect(Post.find(@post_id).title).to eq @new_post["title"]
67 | expect(Post.find(@post_id).content).to eq @new_post["content"]
68 | end
69 | end
70 |
71 | context "without admin rights" do
72 | it "does not update post" do
73 | login(:user)
74 | put :update, params: { id: @post_id, post: @new_post }
75 |
76 | expect(response.message).to eq "Forbidden"
77 | expect(Post.find_by(title: @post["title"]).content).to eq @post["content"]
78 | expect(Post.find_by(title: @new_post["title"])).to be_nil
79 | end
80 | end
81 | end
82 |
83 | describe "DELETE #destroy" do
84 | context "with admin rights" do
85 | it "deletes an existing post by id" do
86 | login(:admin)
87 | delete :destroy, params: { id: @post_id }
88 |
89 | expect(Post.find_by(title: @post["title"])).to be_nil
90 | end
91 | end
92 |
93 | context "without admin rights" do
94 | it "does not delete post" do
95 | login(:user)
96 | delete :destroy, params: { id: @post_id }
97 |
98 | expect(response.message).to eq "Forbidden"
99 | expect(Post.find(@post_id)).to be_truthy
100 | end
101 | end
102 | end
103 | end
104 |
105 | private
106 |
107 | def login(access_level)
108 | allow(AuthorizeApiRequest).to receive_message_chain(:call, :result){ UserAuthorizer.current_user(access_level) }
109 | end
110 |
--------------------------------------------------------------------------------
/spec/controllers/user_authorizer.rb:
--------------------------------------------------------------------------------
1 | class UserAuthorizer
2 | class << self
3 | def current_user(access_level)
4 | current_user = User.new(email: "test@email.com", password: "nopassword")
5 |
6 | current_user.instance_exec(access_level) do |level|
7 | define_singleton_method(:admin?) do
8 | return level == :admin
9 | end
10 | end
11 |
12 | return current_user
13 | end
14 | end
15 | end
16 |
--------------------------------------------------------------------------------
/spec/controllers/users_controller_spec.rb:
--------------------------------------------------------------------------------
1 | RSpec.describe UsersController, type: :controller do
2 | before :each do
3 | @test_user = JSON.parse(file_fixture("users.json").read)["testUser"]
4 | User.create!(@test_user)
5 | end
6 |
7 | describe "POST #register" do
8 | context "with valid attributes" do
9 | it "creates a new user" do
10 | post :register, params: { email: "newuser@email.com", password: "newuser123" }
11 |
12 | expect(response.message).to eq "Created"
13 | expect(User.find_by(email: "newuser@email.com")).to be_truthy
14 | end
15 | end
16 |
17 | context "with invalid attributes" do
18 | it "does not create without email field" do
19 | post :register, params: { password: @test_user["password"] }
20 |
21 | expect(JSON.parse(response.body)).to include("error" => "Bad Request")
22 | end
23 |
24 | it "does not create duplicate user" do
25 | post :register, params: { email: @test_user["email"], password: @test_user["password"] }
26 |
27 | expect(JSON.parse(response.body)).to include("error" => "Bad Request")
28 | end
29 | end
30 | end
31 | end
32 |
--------------------------------------------------------------------------------
/spec/fixtures/files/comments.json:
--------------------------------------------------------------------------------
1 | {
2 | "comment": {
3 | "name": "anonymA",
4 | "message": "foo bar"
5 | },
6 | "newComment": {
7 | "name": "anonymB",
8 | "message": "baz qux"
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/spec/fixtures/files/posts.json:
--------------------------------------------------------------------------------
1 | {
2 | "post": {
3 | "title": "Hello",
4 | "content": "Hello world!"
5 | },
6 | "newPost": {
7 | "title": "Goodbye",
8 | "content": "Goodbye world!"
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/spec/fixtures/files/users.json:
--------------------------------------------------------------------------------
1 | {
2 | "adminUser": {
3 | "email": "admin@email.com",
4 | "password": "admin123",
5 | "admin": true
6 | },
7 | "testUser": {
8 | "email": "testuser@email.com",
9 | "password": "testuser123",
10 | "admin": false
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spec/lib/jwt_service_spec.rb:
--------------------------------------------------------------------------------
1 | RSpec.describe JwtService do
2 | before :each do
3 | @payload = { user_id: 42 }
4 | end
5 |
6 | it "encodes payload correctly" do
7 | token = JwtService.encode(@payload)
8 |
9 | expect(JwtService.decode(token)).to include("user_id" => 42, "exp" => 24.hours.from_now.to_i)
10 | end
11 |
12 | it "decodes token correctly" do
13 | token = JwtService.encode(@payload)
14 | payload = JwtService.decode(token)
15 |
16 | expect(payload["user_id"]).to be 42
17 | expect(payload).to include("exp")
18 | end
19 |
20 | it "returns nil on incorrect token" do
21 | token = "hello.world"
22 |
23 | expect(JwtService.decode(token)).to be_nil
24 | end
25 | end
26 |
--------------------------------------------------------------------------------
/spec/models/comment_spec.rb:
--------------------------------------------------------------------------------
1 | RSpec.describe Comment, type: :model do
2 | it{ should belong_to(:post) }
3 |
4 | it{ should validate_presence_of(:message) }
5 | end
6 |
--------------------------------------------------------------------------------
/spec/models/post_spec.rb:
--------------------------------------------------------------------------------
1 | RSpec.describe Post, type: :model do
2 | it{ should have_many(:comments).dependent(:destroy) }
3 |
4 | it{ should validate_presence_of(:title) }
5 | it{ should validate_presence_of(:content) }
6 | end
7 |
--------------------------------------------------------------------------------
/spec/models/user_spec.rb:
--------------------------------------------------------------------------------
1 | RSpec.describe User, type: :model do
2 | it{ should have_secure_password }
3 |
4 | it{ should validate_presence_of(:email) }
5 |
6 | describe "uniqueness" do
7 | subject{ User.new(email: "test@email.com", password: "nopassword") }
8 | it{ should validate_uniqueness_of(:email) }
9 | end
10 | end
11 |
--------------------------------------------------------------------------------
/spec/rails_helper.rb:
--------------------------------------------------------------------------------
1 | # This file is copied to spec/ when you run 'rails generate rspec:install'
2 | require "spec_helper"
3 | ENV["RAILS_ENV"] ||= "test"
4 | require File.expand_path("../config/environment", __dir__)
5 | # Prevent database truncation if the environment is production
6 | abort("The Rails environment is running in production mode!") if Rails.env.production?
7 | require "rspec/rails"
8 | require "database_cleaner"
9 | # Add additional requires below this line. Rails is not loaded until this point!
10 |
11 | # Requires supporting ruby files with custom matchers and macros, etc, in
12 | # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
13 | # run as spec files by default. This means that files in spec/support that end
14 | # in _spec.rb will both be required and run as specs, causing the specs to be
15 | # run twice. It is recommended that you do not name files matching this glob to
16 | # end with _spec.rb. You can configure this pattern with the --pattern
17 | # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
18 | #
19 | # The following line is provided for convenience purposes. It has the downside
20 | # of increasing the boot-up time by auto-requiring all files in the support
21 | # directory. Alternatively, in the individual `*_spec.rb` files, manually
22 | # require only the support files necessary.
23 | #
24 | # Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
25 |
26 | # Checks for pending migrations and applies them before tests are run.
27 | # If you are not using ActiveRecord, you can remove this line.
28 | ActiveRecord::Migration.maintain_test_schema!
29 |
30 | # configure shoulda matchers to use rspec as the test framework and full matcher libraries for rails
31 | Shoulda::Matchers.configure do |config|
32 | config.integrate do |with|
33 | with.test_framework(:rspec)
34 | with.library(:rails)
35 | end
36 | end
37 |
38 | RSpec.configure do |config|
39 | # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
40 | config.fixture_path = "#{::Rails.root}/spec/fixtures"
41 |
42 | # If you're not using ActiveRecord, or you'd prefer not to run each of your
43 | # examples within a transaction, remove the following line or assign false
44 | # instead of true.
45 | config.use_transactional_fixtures = true
46 |
47 | # RSpec Rails can automatically mix in different behaviours to your tests
48 | # based on their file location, for example enabling you to call `get` and
49 | # `post` in specs under `spec/controllers`.
50 | #
51 | # You can disable this behaviour by removing the line below, and instead
52 | # explicitly tag your specs with their type, e.g.:
53 | #
54 | # RSpec.describe UsersController, :type => :controller do
55 | # # ...
56 | # end
57 | #
58 | # The different available types are documented in the features, such as in
59 | # https://relishapp.com/rspec/rspec-rails/docs
60 | config.infer_spec_type_from_file_location!
61 |
62 | # Filter lines from Rails gems in backtraces.
63 | config.filter_rails_from_backtrace!
64 | # arbitrary gems may also be filtered via:
65 | # config.filter_gems_from_backtrace("gem name")
66 | # start by truncating all the tables but then use the faster transaction strategy the rest of the time.
67 |
68 | config.before(:suite) do
69 | DatabaseCleaner.clean_with(:truncation)
70 | end
71 |
72 | config.before(:each) do
73 | DatabaseCleaner.strategy = :transaction
74 | DatabaseCleaner.start
75 | end
76 |
77 | config.after(:each) do
78 | DatabaseCleaner.clean
79 | end
80 | end
81 |
--------------------------------------------------------------------------------
/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | require_relative "../app/initialize"
2 |
3 | # This file was generated by the `rails generate rspec:install` command. Conventionally, all
4 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5 | # The generated `.rspec` file contains `--require spec_helper` which will cause
6 | # this file to always be loaded, without a need to explicitly require it in any
7 | # files.
8 | #
9 | # Given that it is always loaded, you are encouraged to keep this file as
10 | # light-weight as possible. Requiring heavyweight dependencies from this file
11 | # will add to the boot time of your test suite on EVERY test run, even for an
12 | # individual file that may not need all of that loaded. Instead, consider making
13 | # a separate helper file that requires the additional dependencies and performs
14 | # the additional setup, and require it from the spec files that actually need
15 | # it.
16 | #
17 | # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
18 | RSpec.configure do |config|
19 | # rspec-expectations config goes here. You can use an alternate
20 | # assertion/expectation library such as wrong or the stdlib/minitest
21 | # assertions if you prefer.
22 | config.expect_with(:rspec) do |expectations|
23 | # This option will default to `true` in RSpec 4. It makes the `description`
24 | # and `failure_message` of custom matchers include text for helper methods
25 | # defined using `chain`, e.g.:
26 | # be_bigger_than(2).and_smaller_than(4).description
27 | # # => "be bigger than 2 and smaller than 4"
28 | # ...rather than:
29 | # # => "be bigger than 2"
30 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true
31 | end
32 |
33 | # rspec-mocks config goes here. You can use an alternate test double
34 | # library (such as bogus or mocha) by changing the `mock_with` option here.
35 | config.mock_with(:rspec) do |mocks|
36 | # Prevents you from mocking or stubbing a method that does not exist on
37 | # a real object. This is generally recommended, and will default to
38 | # `true` in RSpec 4.
39 | mocks.verify_partial_doubles = true
40 | end
41 |
42 | # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
43 | # have no way to turn it off -- the option exists only for backwards
44 | # compatibility in RSpec 3). It causes shared context metadata to be
45 | # inherited by the metadata hash of host groups and examples, rather than
46 | # triggering implicit auto-inclusion in groups with matching metadata.
47 | config.shared_context_metadata_behavior = :apply_to_host_groups
48 |
49 | # The settings below are suggested to provide a good initial experience
50 | # with RSpec, but feel free to customize to your heart's content.
51 | # # This allows you to limit a spec run to individual examples or groups
52 | # # you care about by tagging them with `:focus` metadata. When nothing
53 | # # is tagged with `:focus`, all examples get run. RSpec also provides
54 | # # aliases for `it`, `describe`, and `context` that include `:focus`
55 | # # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
56 | # config.filter_run_when_matching :focus
57 | #
58 | # # Allows RSpec to persist some state between runs in order to support
59 | # # the `--only-failures` and `--next-failure` CLI options. We recommend
60 | # # you configure your source control system to ignore this file.
61 | # config.example_status_persistence_file_path = "spec/examples.txt"
62 | #
63 | # # Limits the available syntax to the non-monkey patched syntax that is
64 | # # recommended. For more details, see:
65 | # # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
66 | # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
67 | # # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
68 | # config.disable_monkey_patching!
69 | #
70 | # # Many RSpec users commonly either run the entire suite or an individual
71 | # # file, and it's useful to allow more verbose output when running an
72 | # # individual spec file.
73 | # if config.files_to_run.one?
74 | # # Use the documentation formatter for detailed output,
75 | # # unless a formatter has already been configured
76 | # # (e.g. via a command-line flag).
77 | # config.default_formatter = "doc"
78 | # end
79 | #
80 | # # Print the 10 slowest examples and example groups at the
81 | # # end of the spec run, to help surface which specs are running
82 | # # particularly slow.
83 | # config.profile_examples = 10
84 | #
85 | # # Run specs in random order to surface order dependencies. If you find an
86 | # # order dependency and want to debug it, you can fix the order by providing
87 | # # the seed, which is printed after each run.
88 | # # --seed 1234
89 | # config.order = :random
90 | #
91 | # # Seed global randomization in this process using the `--seed` CLI option.
92 | # # Setting this allows you to use `--seed` to deterministically reproduce
93 | # # test failures related to randomization by passing the same `--seed` value
94 | # # as the one that triggered the failure.
95 | # Kernel.srand config.seed
96 | end
97 |
--------------------------------------------------------------------------------
/tmp/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darkhorse34/rails-rest-api/c6aae062db8b5c85f3a9833168e5a3eb644fdc5f/tmp/.keep
--------------------------------------------------------------------------------
/vendor/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darkhorse34/rails-rest-api/c6aae062db8b5c85f3a9833168e5a3eb644fdc5f/vendor/.keep
--------------------------------------------------------------------------------