restspec 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (202) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +21 -0
  3. data/.gitignore +23 -0
  4. data/.rspec +4 -0
  5. data/Gemfile +4 -0
  6. data/Guardfile +6 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +188 -0
  9. data/ROADMAP.md +11 -0
  10. data/Rakefile +20 -0
  11. data/bin/restspec +54 -0
  12. data/bin/templates/Gemfile +3 -0
  13. data/bin/templates/custom_macros.rb +3 -0
  14. data/bin/templates/restspec_config.rb +10 -0
  15. data/bin/templates/spec_helper.rb +19 -0
  16. data/docs/endpoints.md +200 -0
  17. data/docs/helpers.md +40 -0
  18. data/docs/macros.md +140 -0
  19. data/docs/matchers.md +38 -0
  20. data/docs/schemas.md +28 -0
  21. data/docs/tutorial.md +477 -0
  22. data/docs/types.md +134 -0
  23. data/examples/store-api-tests/.rspec +3 -0
  24. data/examples/store-api-tests/Gemfile +4 -0
  25. data/examples/store-api-tests/Gemfile.lock +70 -0
  26. data/examples/store-api-tests/spec/api/category_spec.rb +23 -0
  27. data/examples/store-api-tests/spec/api/product_spec.rb +55 -0
  28. data/examples/store-api-tests/spec/api/restspec/endpoints.rb +39 -0
  29. data/examples/store-api-tests/spec/api/restspec/requirements.rb +0 -0
  30. data/examples/store-api-tests/spec/api/restspec/restspec_config.rb +6 -0
  31. data/examples/store-api-tests/spec/api/restspec/schemas.rb +11 -0
  32. data/examples/store-api-tests/spec/spec_helper.rb +19 -0
  33. data/examples/store-api-tests/spec/support/custom_macros.rb +3 -0
  34. data/examples/store-api-tests/spec/support/custom_matchers.rb +0 -0
  35. data/examples/store-api/.editorconfig +24 -0
  36. data/examples/store-api/.rbenv-vars.example +3 -0
  37. data/examples/store-api/.rspec +4 -0
  38. data/examples/store-api/.ruby-version +1 -0
  39. data/examples/store-api/Gemfile +58 -0
  40. data/examples/store-api/Gemfile.lock +216 -0
  41. data/examples/store-api/Guardfile +39 -0
  42. data/examples/store-api/README.md +1 -0
  43. data/examples/store-api/Rakefile +6 -0
  44. data/examples/store-api/app/assets/images/.keep +0 -0
  45. data/examples/store-api/app/assets/javascripts/application.js +16 -0
  46. data/examples/store-api/app/assets/javascripts/categories.js.coffee +3 -0
  47. data/examples/store-api/app/assets/javascripts/products.js.coffee +3 -0
  48. data/examples/store-api/app/assets/stylesheets/application.css +15 -0
  49. data/examples/store-api/app/assets/stylesheets/categories.css.scss +3 -0
  50. data/examples/store-api/app/assets/stylesheets/products.css.scss +3 -0
  51. data/examples/store-api/app/assets/stylesheets/scaffolds.css.scss +69 -0
  52. data/examples/store-api/app/controllers/application_controller.rb +5 -0
  53. data/examples/store-api/app/controllers/categories_controller.rb +74 -0
  54. data/examples/store-api/app/controllers/concerns/.keep +0 -0
  55. data/examples/store-api/app/controllers/products_controller.rb +74 -0
  56. data/examples/store-api/app/helpers/application_helper.rb +2 -0
  57. data/examples/store-api/app/helpers/categories_helper.rb +2 -0
  58. data/examples/store-api/app/helpers/products_helper.rb +2 -0
  59. data/examples/store-api/app/mailers/.keep +0 -0
  60. data/examples/store-api/app/models/.keep +0 -0
  61. data/examples/store-api/app/models/category.rb +2 -0
  62. data/examples/store-api/app/models/concerns/.keep +0 -0
  63. data/examples/store-api/app/models/product.rb +3 -0
  64. data/examples/store-api/app/views/categories/_form.html.erb +21 -0
  65. data/examples/store-api/app/views/categories/edit.html.erb +6 -0
  66. data/examples/store-api/app/views/categories/index.html.erb +25 -0
  67. data/examples/store-api/app/views/categories/index.json.jbuilder +4 -0
  68. data/examples/store-api/app/views/categories/new.html.erb +5 -0
  69. data/examples/store-api/app/views/categories/show.html.erb +9 -0
  70. data/examples/store-api/app/views/categories/show.json.jbuilder +1 -0
  71. data/examples/store-api/app/views/layouts/application.html.erb +14 -0
  72. data/examples/store-api/app/views/products/_form.html.erb +29 -0
  73. data/examples/store-api/app/views/products/edit.html.erb +6 -0
  74. data/examples/store-api/app/views/products/index.html.erb +29 -0
  75. data/examples/store-api/app/views/products/index.json.jbuilder +4 -0
  76. data/examples/store-api/app/views/products/new.html.erb +5 -0
  77. data/examples/store-api/app/views/products/show.html.erb +19 -0
  78. data/examples/store-api/app/views/products/show.json.jbuilder +6 -0
  79. data/examples/store-api/bin/bundle +3 -0
  80. data/examples/store-api/bin/guard +16 -0
  81. data/examples/store-api/bin/rails +8 -0
  82. data/examples/store-api/bin/rake +8 -0
  83. data/examples/store-api/bin/spring +18 -0
  84. data/examples/store-api/config.ru +4 -0
  85. data/examples/store-api/config/application.rb +30 -0
  86. data/examples/store-api/config/boot.rb +4 -0
  87. data/examples/store-api/config/database.yml +25 -0
  88. data/examples/store-api/config/environment.rb +5 -0
  89. data/examples/store-api/config/environments/development.rb +37 -0
  90. data/examples/store-api/config/environments/production.rb +78 -0
  91. data/examples/store-api/config/environments/test.rb +39 -0
  92. data/examples/store-api/config/initializers/assets.rb +8 -0
  93. data/examples/store-api/config/initializers/backtrace_silencers.rb +7 -0
  94. data/examples/store-api/config/initializers/cookies_serializer.rb +3 -0
  95. data/examples/store-api/config/initializers/filter_parameter_logging.rb +4 -0
  96. data/examples/store-api/config/initializers/inflections.rb +16 -0
  97. data/examples/store-api/config/initializers/mime_types.rb +4 -0
  98. data/examples/store-api/config/initializers/session_store.rb +3 -0
  99. data/examples/store-api/config/initializers/wrap_parameters.rb +14 -0
  100. data/examples/store-api/config/locales/en.yml +23 -0
  101. data/examples/store-api/config/routes.rb +59 -0
  102. data/examples/store-api/config/secrets.yml +22 -0
  103. data/examples/store-api/db/migrate/20141205154816_create_products.rb +11 -0
  104. data/examples/store-api/db/migrate/20141205171104_create_categories.rb +9 -0
  105. data/examples/store-api/db/migrate/20141205171140_add_category_id_to_products.rb +5 -0
  106. data/examples/store-api/db/schema.rb +31 -0
  107. data/examples/store-api/db/seeds.rb +7 -0
  108. data/examples/store-api/lib/assets/.keep +0 -0
  109. data/examples/store-api/lib/tasks/.keep +0 -0
  110. data/examples/store-api/log/.keep +0 -0
  111. data/examples/store-api/public/404.html +67 -0
  112. data/examples/store-api/public/422.html +67 -0
  113. data/examples/store-api/public/500.html +66 -0
  114. data/examples/store-api/public/favicon.ico +0 -0
  115. data/examples/store-api/public/robots.txt +5 -0
  116. data/examples/store-api/spec/controllers/categories_controller_spec.rb +159 -0
  117. data/examples/store-api/spec/controllers/products_controller_spec.rb +159 -0
  118. data/examples/store-api/spec/factories/categories.rb +6 -0
  119. data/examples/store-api/spec/factories/products.rb +8 -0
  120. data/examples/store-api/spec/helpers/categories_helper_spec.rb +15 -0
  121. data/examples/store-api/spec/helpers/products_helper_spec.rb +15 -0
  122. data/examples/store-api/spec/models/category_spec.rb +5 -0
  123. data/examples/store-api/spec/models/product_spec.rb +5 -0
  124. data/examples/store-api/spec/rails_helper.rb +50 -0
  125. data/examples/store-api/spec/requests/categories_spec.rb +10 -0
  126. data/examples/store-api/spec/requests/products_spec.rb +10 -0
  127. data/examples/store-api/spec/routing/categories_routing_spec.rb +35 -0
  128. data/examples/store-api/spec/routing/products_routing_spec.rb +35 -0
  129. data/examples/store-api/spec/spec_helper.rb +85 -0
  130. data/examples/store-api/spec/views/categories/edit.html.erb_spec.rb +18 -0
  131. data/examples/store-api/spec/views/categories/index.html.erb_spec.rb +19 -0
  132. data/examples/store-api/spec/views/categories/new.html.erb_spec.rb +18 -0
  133. data/examples/store-api/spec/views/categories/show.html.erb_spec.rb +14 -0
  134. data/examples/store-api/spec/views/products/edit.html.erb_spec.rb +24 -0
  135. data/examples/store-api/spec/views/products/index.html.erb_spec.rb +25 -0
  136. data/examples/store-api/spec/views/products/new.html.erb_spec.rb +24 -0
  137. data/examples/store-api/spec/views/products/show.html.erb_spec.rb +18 -0
  138. data/examples/store-api/vendor/assets/javascripts/.keep +0 -0
  139. data/examples/store-api/vendor/assets/stylesheets/.keep +0 -0
  140. data/lib/restspec.rb +38 -0
  141. data/lib/restspec/configuration.rb +43 -0
  142. data/lib/restspec/endpoints/dsl.rb +142 -0
  143. data/lib/restspec/endpoints/endpoint.rb +135 -0
  144. data/lib/restspec/endpoints/namespace.rb +89 -0
  145. data/lib/restspec/endpoints/network.rb +39 -0
  146. data/lib/restspec/endpoints/request.rb +11 -0
  147. data/lib/restspec/endpoints/response.rb +53 -0
  148. data/lib/restspec/requirements/dsl.rb +10 -0
  149. data/lib/restspec/requirements/requirement.rb +59 -0
  150. data/lib/restspec/rspec/api_helpers.rb +64 -0
  151. data/lib/restspec/rspec/api_macros.rb +126 -0
  152. data/lib/restspec/rspec/extras.rb +2 -0
  153. data/lib/restspec/rspec/matchers/api_matchers.rb +6 -0
  154. data/lib/restspec/rspec/matchers/be_like_schema.rb +18 -0
  155. data/lib/restspec/rspec/matchers/be_like_schema_array.rb +18 -0
  156. data/lib/restspec/rspec/matchers/have_header.rb +47 -0
  157. data/lib/restspec/rspec/matchers/have_status.rb +17 -0
  158. data/lib/restspec/rspec/matchers/include_where.rb +14 -0
  159. data/lib/restspec/rspec/shared_examples.rb +12 -0
  160. data/lib/restspec/schema/attribute.rb +31 -0
  161. data/lib/restspec/schema/attribute_example.rb +21 -0
  162. data/lib/restspec/schema/checker.rb +73 -0
  163. data/lib/restspec/schema/dsl.rb +36 -0
  164. data/lib/restspec/schema/schema.rb +21 -0
  165. data/lib/restspec/schema/schema_example.rb +28 -0
  166. data/lib/restspec/schema/types.rb +35 -0
  167. data/lib/restspec/schema/types/array_type.rb +34 -0
  168. data/lib/restspec/schema/types/basic_type.rb +35 -0
  169. data/lib/restspec/schema/types/boolean_type.rb +11 -0
  170. data/lib/restspec/schema/types/decimal_string_type.rb +32 -0
  171. data/lib/restspec/schema/types/decimal_type.rb +14 -0
  172. data/lib/restspec/schema/types/embedded_schema_type.rb +28 -0
  173. data/lib/restspec/schema/types/hash_type.rb +25 -0
  174. data/lib/restspec/schema/types/integer_type.rb +11 -0
  175. data/lib/restspec/schema/types/null_type.rb +11 -0
  176. data/lib/restspec/schema/types/one_of_type.rb +21 -0
  177. data/lib/restspec/schema/types/schema_id_type.rb +88 -0
  178. data/lib/restspec/schema/types/string_type.rb +11 -0
  179. data/lib/restspec/shortcuts.rb +8 -0
  180. data/lib/restspec/stores/endpoint_store.rb +25 -0
  181. data/lib/restspec/stores/namespace_store.rb +20 -0
  182. data/lib/restspec/stores/schema_store.rb +19 -0
  183. data/lib/restspec/values/status_code.rb +13 -0
  184. data/lib/restspec/values/super_hash.rb +12 -0
  185. data/lib/restspec/version.rb +3 -0
  186. data/restspec.gemspec +37 -0
  187. data/spec/restspec/endpoints/dsl_spec.rb +269 -0
  188. data/spec/restspec/endpoints/endpoint_spec.rb +146 -0
  189. data/spec/restspec/endpoints/namespace_spec.rb +143 -0
  190. data/spec/restspec/endpoints/response_spec.rb +49 -0
  191. data/spec/restspec/schema/attribute_example_spec.rb +35 -0
  192. data/spec/restspec/schema/dsl_spec.rb +78 -0
  193. data/spec/restspec/schema/schema_example_spec.rb +40 -0
  194. data/spec/restspec/schema/schema_spec.rb +11 -0
  195. data/spec/restspec/schema/types/array_type_spec.rb +56 -0
  196. data/spec/restspec/schema/types/basic_type_spec.rb +62 -0
  197. data/spec/restspec/schema/types/boolean_type_spec.rb +26 -0
  198. data/spec/restspec/schema/types/null_type_spec.rb +25 -0
  199. data/spec/restspec/schema/types/string_type_spec.rb +26 -0
  200. data/spec/restspec/values/status_code_spec.rb +13 -0
  201. data/spec/spec_helper.rb +23 -0
  202. metadata +484 -0
@@ -0,0 +1,134 @@
1
+ # Types Documentation
2
+
3
+ ## Types Composition
4
+
5
+ ### Disjunction
6
+
7
+ You can make a logical OR on types using `|`. In this way, an attribute can have a type or another. It generates information from the first type but, when validating, the check goes first to the first type and, if it fails, go to the next one. With this, you can do something like this:
8
+
9
+ ```ruby
10
+ attribute :name, string | null
11
+ ```
12
+
13
+ ### Generic Types
14
+
15
+ With the `of` method you can attach a type information into another type. Every time can decide if it does something with the aditional type. For example, the `array` type can look for the types of each one of his elements using `of`, in this way:
16
+
17
+ ```ruby
18
+ schema :raffle do
19
+ attribute :name, string
20
+ attribute :participants, array.of(embedded_schema(:person))
21
+ end
22
+ ```
23
+
24
+ ## Types
25
+
26
+ ### Array Type
27
+
28
+ - It uses the method `array`.
29
+ - It tests if the current attribute value is an array.
30
+ - Currently, it generates an array depending on the length option and the parameterized type (specified with `of`) being used.
31
+ - It only has the `length` option, that is fixed number.
32
+ - It can be composed of other types using `of`. With `of`, it can test the content of the array more deeply.
33
+
34
+ ```ruby
35
+ attribute :matrix, array.of(array.of(decimal | decimal_string))
36
+ ```
37
+
38
+
39
+ ### Boolean Type
40
+
41
+ - It uses the method `boolean`.
42
+ - It tests if the current attribute value is `true` or `false`.
43
+ - It generates randomly `true` or `false`.
44
+ - It doesn't use any option.
45
+
46
+ ### Decimal String Type
47
+
48
+ - It uses the method `decimal_string`.
49
+ - It tests if the current attribute value is a string that looks like a decimal. (Eg: `"0.1"`)
50
+ - It generates a decimal wrapped into a string.
51
+ - It uses the following options:
52
+ + Example Options:
53
+ * **integer_part:** It specifies the integer part of the generated number.
54
+ * **decimal_part:** It specifies the decimal part of the generated number.
55
+ + Schema Options:
56
+ * **integer_part:** It specifies the expected integer part size of the given attribute value.
57
+ * **decimal_part:** It verifies the expected decimal part size of the given attribute value.
58
+
59
+ ### Decimal Type
60
+
61
+ - It uses the method `decimal`.
62
+ - In only tests if the attribute value is numeric.
63
+ - It generates a decimal number.
64
+ - It uses the following options:
65
+ + Example Options:
66
+ * **integer_part:** It specifies the integer part of the generated number.
67
+ * **decimal_part:** It specifies the decimal part of the generated number.
68
+
69
+ ### Hash Type
70
+
71
+ - It uses the method `hash`.
72
+ - It tests if the attribute is a hash containing some optional keys with an optional value type.
73
+ - Currently, it generates an empty hash. (We should think further if they should generate more than this, and how)
74
+ - It uses the following options:
75
+ + Schema Options:
76
+ * **keys:** Array of keys that should be in the hash.
77
+ * **value_type:** Type (method used by the type) of the values of the hash. With this, `hash` can be composed of other types.
78
+
79
+ ### Integer Type
80
+
81
+ - It uses the method `integer`.
82
+ - In only tests if the attribute value is a fixed number.
83
+ - It generates a random integer number.
84
+ - It doesn't use any option.
85
+
86
+ ### Null Type
87
+
88
+ - It uses the method `null`.
89
+ - It only test for null values.
90
+ - It always generates null.
91
+ - It doesn't use any option.
92
+ - It's useful composed with any other type. For example, for a value that can a string but it's optional.
93
+
94
+ ```ruby
95
+ attribute :address, string | null
96
+ ```
97
+
98
+ ### 'One Of' Type
99
+ - It uses the method `one_of`.
100
+ - It checks if the attribute values is one of the items specified in the `elements` array option.
101
+ - It returns one of the items in the `elements` array option.
102
+ - It only has the `elements` option.
103
+
104
+ ```ruby
105
+ attribute :type, one_of(elements: ['water', 'fire', 'thunder', 'psychic'])
106
+ ```
107
+
108
+ ### 'Schema Id' Type
109
+
110
+ - It uses the method `schema_id`. The first parameter of this method is the main schema to test.
111
+ - It checks if the attribute value is an id of some element in the `index` endpoint associated to the given schema.
112
+ - It generates an object by fetching one item in the `index` endpoint. If there's no item in that endpoint, it will create one item using the `create` endpoint. After this, it will return the id of the item.
113
+ - It uses the following options:
114
+ + Schema Options:
115
+ * **perform_validation:** A boolean to specify if we should perform a schema validation or not. (In case we only want to generate information for tests but not to check against anytime).
116
+ + Example Options:
117
+ * **create_schema:** Name of the schema used to generate data.
118
+ * **hardcoded_fallback:** If we can't get or create the id, this option will be used instead of raise an error.
119
+ * **fetch_endpoint:** The endpoint to use to fetch. By default, it's the `index` endpoint of the namespace asociated with this schema.
120
+ * **create_endpoint:** The endpoint to use to create data. By default, it's the `create` endpoint of the namespace asociated with this schema.
121
+
122
+ ### String Type
123
+
124
+ - It uses the method `string`.
125
+ - It tests if the current attribute value is a string.
126
+ - It generates a random word.
127
+ - It doesn't use any option.
128
+
129
+ ### Embedded Schema
130
+
131
+ - It uses the method `embedded_schema` with the name of the schema to embed.
132
+ - It tests if the current attribute is a hash that have the shape of the schema.
133
+ - It generates an example of the given schema.
134
+ - It doesn't use any option.
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=doc
3
+
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'pry'
4
+ gem 'restspec', path: '~/dev/projects/ruby/restspec'
@@ -0,0 +1,70 @@
1
+ PATH
2
+ remote: ~/dev/projects/ruby/restspec
3
+ specs:
4
+ restspec (0.0.1)
5
+ activesupport (~> 4.0)
6
+ faker (~> 1.4)
7
+ hashie (~> 3.3)
8
+ httparty (~> 0.13)
9
+ rack (~> 1.0)
10
+ rspec (~> 3.0)
11
+ rspec-collection_matchers (~> 1.0)
12
+ rspec-its (~> 1.0)
13
+ thor (~> 0.19)
14
+
15
+ GEM
16
+ remote: https://rubygems.org/
17
+ specs:
18
+ activesupport (4.1.7)
19
+ i18n (~> 0.6, >= 0.6.9)
20
+ json (~> 1.7, >= 1.7.7)
21
+ minitest (~> 5.1)
22
+ thread_safe (~> 0.1)
23
+ tzinfo (~> 1.1)
24
+ coderay (1.1.0)
25
+ diff-lcs (1.2.5)
26
+ faker (1.4.3)
27
+ i18n (~> 0.5)
28
+ hashie (3.3.1)
29
+ httparty (0.13.3)
30
+ json (~> 1.8)
31
+ multi_xml (>= 0.5.2)
32
+ i18n (0.6.11)
33
+ json (1.8.1)
34
+ method_source (0.8.2)
35
+ minitest (5.4.3)
36
+ multi_xml (0.5.5)
37
+ pry (0.10.1)
38
+ coderay (~> 1.1.0)
39
+ method_source (~> 0.8.1)
40
+ slop (~> 3.4)
41
+ rack (1.5.2)
42
+ rspec (3.1.0)
43
+ rspec-core (~> 3.1.0)
44
+ rspec-expectations (~> 3.1.0)
45
+ rspec-mocks (~> 3.1.0)
46
+ rspec-collection_matchers (1.0.0)
47
+ rspec-expectations (>= 2.99.0.beta1)
48
+ rspec-core (3.1.7)
49
+ rspec-support (~> 3.1.0)
50
+ rspec-expectations (3.1.2)
51
+ diff-lcs (>= 1.2.0, < 2.0)
52
+ rspec-support (~> 3.1.0)
53
+ rspec-its (1.1.0)
54
+ rspec-core (>= 3.0.0)
55
+ rspec-expectations (>= 3.0.0)
56
+ rspec-mocks (3.1.3)
57
+ rspec-support (~> 3.1.0)
58
+ rspec-support (3.1.2)
59
+ slop (3.6.0)
60
+ thor (0.19.1)
61
+ thread_safe (0.3.4)
62
+ tzinfo (1.2.2)
63
+ thread_safe (~> 0.1)
64
+
65
+ PLATFORMS
66
+ ruby
67
+
68
+ DEPENDENCIES
69
+ pry
70
+ restspec!
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe :categories, :type => :api do
4
+ endpoint 'categories/create' do
5
+ test do
6
+ payload { schema_example(:category) }
7
+
8
+ it { should have_status(:created) }
9
+ end
10
+ end
11
+
12
+ endpoint 'categories/products', focus: true do
13
+ test do
14
+ # it { should have_status(:ok) }
15
+ # it { should be_like_schema_array }
16
+ end
17
+
18
+ test 'with an unexisting category' do
19
+ url_params id: '0'
20
+ it { should have_status(:not_found) }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe :products, :type => :api do
4
+ endpoint 'products/create' do
5
+ test do
6
+ payload { schema_example(:product) }
7
+
8
+ it { should have_status(:created) }
9
+ end
10
+ end
11
+
12
+ endpoint 'products/show' do
13
+ test do
14
+ it { should have_status(:ok) }
15
+ it { should be_like_schema }
16
+ end
17
+ end
18
+
19
+ endpoint 'products/index' do
20
+ test do
21
+ it { should have_status(:ok) }
22
+ it { should be_like_schema_array }
23
+ end
24
+ end
25
+
26
+ endpoint 'products/update', resource: 'products/show' do
27
+ payload { { name: "#{initial_resource.name}-001" } }
28
+
29
+ test do
30
+ it 'updates the name' do
31
+ expect(final_resource.name).to_not eq(initial_resource.name)
32
+ expect(final_resource.name).to eq(request.payload.name)
33
+ end
34
+
35
+ it 'includes the payload' do
36
+ expect(final_resource).to include(payload)
37
+ end
38
+
39
+ it 'does not include the initial resource attributes' do
40
+ expect(final_resource.values).to_not include(initial_resource.values)
41
+ end
42
+ end
43
+ end
44
+
45
+ endpoint 'products/destroy', resource: 'products/show' do
46
+ test do
47
+ it { should have_status(:no_content) }
48
+
49
+ it 'actually destroyed the product' do
50
+ resource_after_destruction = resource_endpoint.execute
51
+ expect(resource_after_destruction).to have_status(:not_found)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,39 @@
1
+ resource :products do
2
+ schema :product
3
+
4
+ collection do
5
+ post :create
6
+ get :index do
7
+ schema :product, without: [:category]
8
+ end
9
+ end
10
+
11
+ member do
12
+ url_param(:id) { schema_id(:product) }
13
+
14
+ get :show
15
+ put :update
16
+ delete :destroy
17
+ end
18
+ end
19
+
20
+ resource :categories do
21
+ schema :category
22
+
23
+ collection do
24
+ post :create
25
+ get :index
26
+ end
27
+
28
+ member do
29
+ url_param(:id) { schema_id(:category) }
30
+
31
+ get :show
32
+ put :update
33
+ delete :destroy
34
+
35
+ get :products, '/products' do
36
+ schema :product
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,6 @@
1
+ Restspec.configure do |config|
2
+ config.base_url = 'http://localhost:3000'
3
+ config.schema_definition = "#{File.dirname __FILE__}/schemas.rb"
4
+ config.endpoints_definition = "#{File.dirname __FILE__}/endpoints.rb"
5
+ config.requirements_definition = "#{File.dirname __FILE__}/requirements.rb"
6
+ end
@@ -0,0 +1,11 @@
1
+ schema :product do
2
+ attribute :name, string
3
+ attribute :code, string
4
+ attribute :price, decimal | decimal_string
5
+ attribute :category_id, schema_id(:category)
6
+ attribute :category, embedded_schema(:category), :for => [:checks]
7
+ end
8
+
9
+ schema :category do
10
+ attribute :name, string
11
+ end
@@ -0,0 +1,19 @@
1
+ require 'restspec'
2
+
3
+ Dir["#{File.dirname __FILE__}/support/**/*.rb"].each {|f| require f}
4
+
5
+ RSpec.configure do |config|
6
+ config.expect_with :rspec do |expectations|
7
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
8
+ end
9
+
10
+ config.mock_with :rspec do |mocks|
11
+ mocks.verify_partial_doubles = true
12
+ end
13
+
14
+ config.include Restspec::RSpec::ApiHelpers, :type => :api
15
+ config.extend Restspec::RSpec::ApiMacros, :type => :api
16
+ config.extend CustomMacros, :type => :api
17
+ end
18
+
19
+ require_relative './api/restspec/restspec_config'
@@ -0,0 +1,3 @@
1
+ module CustomMacros
2
+
3
+ end
@@ -0,0 +1,24 @@
1
+ # EditorConfig helps developers define and maintain consistent
2
+ # coding styles between different editors and IDEs
3
+ # editorconfig.org
4
+
5
+ root = true
6
+
7
+ [*]
8
+
9
+ # Change these settings to your own preference
10
+ indent_style = space
11
+ indent_size = 2
12
+
13
+ # We recommend you to keep these unchanged
14
+ end_of_line = lf
15
+ charset = utf-8
16
+ trim_trailing_whitespace = true
17
+ insert_final_newline = true
18
+
19
+ [*.js]
20
+ indent_style = tab
21
+ indent_size = 4
22
+
23
+ [*.md]
24
+ trim_trailing_whitespace = false
@@ -0,0 +1,3 @@
1
+ DEV_DB_NAME=store-api
2
+ DEV_DB_USER=root
3
+ DEV_DB_PASSWORD=
@@ -0,0 +1,4 @@
1
+ --color
2
+ --require spec_helper
3
+ --format=doc
4
+ --format=Nc
@@ -0,0 +1 @@
1
+ 2.0.0-p353
@@ -0,0 +1,58 @@
1
+ source 'https://rubygems.org'
2
+
3
+
4
+ # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
5
+ gem 'rails', '4.1.6'
6
+ # Use sqlite3 as the database for Active Record
7
+ gem 'sqlite3'
8
+ # Use SCSS for stylesheets
9
+ gem 'sass-rails', '~> 4.0.3'
10
+ # Use Uglifier as compressor for JavaScript assets
11
+ gem 'uglifier', '>= 1.3.0'
12
+ # Use CoffeeScript for .js.coffee assets and views
13
+ gem 'coffee-rails', '~> 4.0.0'
14
+ # See https://github.com/sstephenson/execjs#readme for more supported runtimes
15
+ # gem 'therubyracer', platforms: :ruby
16
+
17
+ # Use jquery as the JavaScript library
18
+ gem 'jquery-rails'
19
+ # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
20
+ gem 'turbolinks'
21
+ # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
22
+ gem 'jbuilder', '~> 2.0'
23
+ # bundle exec rake doc:rails generates the API under doc/api.
24
+ gem 'sdoc', '~> 0.4.0', group: :doc
25
+
26
+ # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
27
+ gem 'spring', group: :development
28
+
29
+ # Use ActiveModel has_secure_password
30
+ # gem 'bcrypt', '~> 3.1.7'
31
+
32
+ # Use unicorn as the app server
33
+ # gem 'unicorn'
34
+
35
+ # Use Capistrano for deployment
36
+ # gem 'capistrano-rails', group: :development
37
+
38
+ # Use debugger
39
+ # gem 'debugger', group: [:development, :test]
40
+
41
+
42
+ group :development, :test do
43
+ gem "rspec-rails"
44
+ gem "factory_girl_rails"
45
+ gem "byebug"
46
+ gem "zeus"
47
+ gem "guard-rspec", require: false
48
+ gem "rspec-nc", require: false
49
+ gem "pry-rails"
50
+ gem "faker"
51
+ gem "quiet_assets"
52
+ gem "better_errors"
53
+ gem "binding_of_caller"
54
+ end
55
+
56
+ group :test do
57
+ gem "shoulda-matchers"
58
+ end