cuprum-rails 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +145 -0
- data/DEVELOPMENT.md +20 -0
- data/README.md +356 -63
- data/lib/cuprum/rails/action.rb +32 -16
- data/lib/cuprum/rails/actions/create.rb +62 -15
- data/lib/cuprum/rails/actions/destroy.rb +23 -7
- data/lib/cuprum/rails/actions/edit.rb +23 -7
- data/lib/cuprum/rails/actions/index.rb +30 -10
- data/lib/cuprum/rails/actions/middleware/associations/cache.rb +112 -0
- data/lib/cuprum/rails/actions/middleware/associations/find.rb +23 -0
- data/lib/cuprum/rails/actions/middleware/associations/parent.rb +70 -0
- data/lib/cuprum/rails/actions/middleware/associations/query.rb +140 -0
- data/lib/cuprum/rails/actions/middleware/associations.rb +12 -0
- data/lib/cuprum/rails/actions/middleware/log_request.rb +126 -0
- data/lib/cuprum/rails/actions/middleware/log_result.rb +51 -0
- data/lib/cuprum/rails/actions/middleware/resources/find.rb +44 -0
- data/lib/cuprum/rails/actions/middleware/resources/query.rb +91 -0
- data/lib/cuprum/rails/actions/middleware/resources.rb +11 -0
- data/lib/cuprum/rails/actions/middleware.rb +13 -0
- data/lib/cuprum/rails/actions/new.rb +16 -4
- data/lib/cuprum/rails/actions/parameter_validation.rb +60 -0
- data/lib/cuprum/rails/actions/resource_action.rb +119 -42
- data/lib/cuprum/rails/actions/show.rb +23 -7
- data/lib/cuprum/rails/actions/update.rb +70 -22
- data/lib/cuprum/rails/actions.rb +11 -7
- data/lib/cuprum/rails/collection.rb +27 -47
- data/lib/cuprum/rails/command.rb +3 -1
- data/lib/cuprum/rails/commands/destroy_one.rb +10 -6
- data/lib/cuprum/rails/commands/find_many.rb +8 -1
- data/lib/cuprum/rails/commands/find_matching.rb +1 -1
- data/lib/cuprum/rails/commands/find_one.rb +8 -0
- data/lib/cuprum/rails/commands/insert_one.rb +17 -6
- data/lib/cuprum/rails/commands/update_one.rb +16 -5
- data/lib/cuprum/rails/constraints/parameters_contract.rb +14 -0
- data/lib/cuprum/rails/constraints.rb +10 -0
- data/lib/cuprum/rails/controller.rb +12 -2
- data/lib/cuprum/rails/controllers/action.rb +100 -0
- data/lib/cuprum/rails/controllers/class_methods/actions.rb +33 -7
- data/lib/cuprum/rails/controllers/class_methods/configuration.rb +36 -0
- data/lib/cuprum/rails/controllers/class_methods/middleware.rb +88 -0
- data/lib/cuprum/rails/controllers/class_methods/validations.rb +2 -2
- data/lib/cuprum/rails/controllers/configuration.rb +41 -1
- data/lib/cuprum/rails/controllers/middleware.rb +59 -0
- data/lib/cuprum/rails/controllers.rb +2 -0
- data/lib/cuprum/rails/errors/invalid_parameters.rb +55 -0
- data/lib/cuprum/rails/errors/invalid_statement.rb +11 -0
- data/lib/cuprum/rails/errors/missing_parameter.rb +42 -0
- data/lib/cuprum/rails/errors/resource_error.rb +46 -0
- data/lib/cuprum/rails/errors.rb +6 -1
- data/lib/cuprum/rails/map_errors.rb +29 -1
- data/lib/cuprum/rails/query.rb +1 -1
- data/lib/cuprum/rails/repository.rb +12 -25
- data/lib/cuprum/rails/request.rb +149 -60
- data/lib/cuprum/rails/resource.rb +119 -85
- data/lib/cuprum/rails/responders/base_responder.rb +78 -0
- data/lib/cuprum/rails/responders/html/plural_resource.rb +9 -39
- data/lib/cuprum/rails/responders/html/rendering.rb +81 -0
- data/lib/cuprum/rails/responders/html/resource.rb +107 -0
- data/lib/cuprum/rails/responders/html/singular_resource.rb +9 -38
- data/lib/cuprum/rails/responders/html.rb +2 -0
- data/lib/cuprum/rails/responders/html_responder.rb +8 -52
- data/lib/cuprum/rails/responders/json/resource.rb +3 -3
- data/lib/cuprum/rails/responders/json_responder.rb +31 -16
- data/lib/cuprum/rails/responders/matching.rb +29 -27
- data/lib/cuprum/rails/responders/serialization.rb +11 -9
- data/lib/cuprum/rails/responders.rb +1 -0
- data/lib/cuprum/rails/responses/head_response.rb +24 -0
- data/lib/cuprum/rails/responses/html/redirect_back_response.rb +55 -0
- data/lib/cuprum/rails/responses/html/redirect_response.rb +19 -4
- data/lib/cuprum/rails/responses/html/render_response.rb +17 -5
- data/lib/cuprum/rails/responses/html.rb +6 -2
- data/lib/cuprum/rails/responses.rb +1 -0
- data/lib/cuprum/rails/result.rb +36 -0
- data/lib/cuprum/rails/routes.rb +36 -23
- data/lib/cuprum/rails/rspec/contract_helpers.rb +57 -0
- data/lib/cuprum/rails/rspec/contracts/action_contracts.rb +754 -0
- data/lib/cuprum/rails/rspec/contracts/actions/create_contracts.rb +289 -0
- data/lib/cuprum/rails/rspec/contracts/actions/destroy_contracts.rb +164 -0
- data/lib/cuprum/rails/rspec/contracts/actions/edit_contracts.rb +73 -0
- data/lib/cuprum/rails/rspec/contracts/actions/index_contracts.rb +108 -0
- data/lib/cuprum/rails/rspec/contracts/actions/new_contracts.rb +111 -0
- data/lib/cuprum/rails/rspec/contracts/actions/show_contracts.rb +72 -0
- data/lib/cuprum/rails/rspec/contracts/actions/update_contracts.rb +263 -0
- data/lib/cuprum/rails/rspec/contracts/actions.rb +8 -0
- data/lib/cuprum/rails/rspec/contracts/command_contracts.rb +479 -0
- data/lib/cuprum/rails/rspec/contracts/responder_contracts.rb +232 -0
- data/lib/cuprum/rails/rspec/contracts/routes_contracts.rb +363 -0
- data/lib/cuprum/rails/rspec/contracts/serializers_contracts.rb +70 -0
- data/lib/cuprum/rails/rspec/contracts.rb +8 -0
- data/lib/cuprum/rails/rspec/matchers/be_a_result_matcher.rb +64 -0
- data/lib/cuprum/rails/rspec/matchers.rb +41 -0
- data/lib/cuprum/rails/serializers/base_serializer.rb +60 -0
- data/lib/cuprum/rails/serializers/context.rb +84 -0
- data/lib/cuprum/rails/serializers/json/active_record_serializer.rb +2 -2
- data/lib/cuprum/rails/serializers/json/array_serializer.rb +9 -8
- data/lib/cuprum/rails/serializers/json/attributes_serializer.rb +95 -172
- data/lib/cuprum/rails/serializers/json/error_serializer.rb +2 -2
- data/lib/cuprum/rails/serializers/json/hash_serializer.rb +9 -8
- data/lib/cuprum/rails/serializers/json/identity_serializer.rb +3 -3
- data/lib/cuprum/rails/serializers/json/properties_serializer.rb +252 -0
- data/lib/cuprum/rails/serializers/json.rb +2 -1
- data/lib/cuprum/rails/serializers.rb +3 -1
- data/lib/cuprum/rails/version.rb +1 -1
- data/lib/cuprum/rails.rb +19 -16
- metadata +73 -131
- data/lib/cuprum/rails/controller_action.rb +0 -121
- data/lib/cuprum/rails/errors/missing_parameters.rb +0 -33
- data/lib/cuprum/rails/errors/missing_primary_key.rb +0 -46
- data/lib/cuprum/rails/errors/undefined_permitted_attributes.rb +0 -34
- data/lib/cuprum/rails/rspec/command_contract.rb +0 -460
- data/lib/cuprum/rails/rspec/define_route_contract.rb +0 -84
- data/lib/cuprum/rails/serializers/json/serializer.rb +0 -66
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a11b779042715de20325d94601faa030c4c87222255feb97413f3394dbcd616
|
4
|
+
data.tar.gz: 7515ee3e188e48489b04e0cca7ac91a0f2a282a783a294ccdd10b920ae91c0d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1e000dc78e44d587c1185361c42f5cd75a151400dde79a963d3d779aeebadf1a8257727eccad0b5c15493be301f2687ad1ecd8705059043e53f0cd615b86637
|
7
|
+
data.tar.gz: dfde0bdb1c6a265c700412ef8174a62e1f3ccba3de7841c0da8af07069c987a05566eac98fe79b6dd20ae7b132c9d6e3ac8d607a89f11da16f9fc53a50db4a73
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,150 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## O.2.0
|
4
|
+
|
5
|
+
### Actions
|
6
|
+
|
7
|
+
Implemented `#transaction` method.
|
8
|
+
|
9
|
+
Refactored how actions handle required parameters.
|
10
|
+
|
11
|
+
- The validation errors for the `Create` and `Update` actions are now scoped by the resource name. The error path should now match the relative path of the corresponding form field.
|
12
|
+
|
13
|
+
- **(Breaking Change)** Action constructors no longer accept `:repository` or `:resource` keywords by default.
|
14
|
+
|
15
|
+
- **(Breaking Change)** Actions now require a `:repository` keyword when called, and can accept arbitrary keywords.
|
16
|
+
|
17
|
+
- **(Breaking Change)** Resource actions now require a `:resource` keyword when called.
|
18
|
+
|
19
|
+
#### Middleware
|
20
|
+
|
21
|
+
- Defined `Actions::Middleware::Associations::Find` for querying associations.
|
22
|
+
- Defined `Actions::Middleware::Associations::Parent` for querying a parent `belongs_to` association.
|
23
|
+
- Defines `Actions::Middleware::LogRequest` for logging request details.
|
24
|
+
- Defines `Actions::Middleware::LogResult` for logging the action result.
|
25
|
+
|
26
|
+
### Collections
|
27
|
+
|
28
|
+
Implemented `Collection#qualified_path`, and added qualified path support to `Repository`.
|
29
|
+
|
30
|
+
#### Commands
|
31
|
+
|
32
|
+
Commands now handle invalid SQL statement exceptions by returning a failing result with a `StatementInvalid` error, rather than raising the exception.
|
33
|
+
|
34
|
+
### Controllers
|
35
|
+
|
36
|
+
Implemented `.build_request` class method.
|
37
|
+
|
38
|
+
Implemented `.default_format` configuration option.
|
39
|
+
|
40
|
+
Refactored `Cuprum::Rails::ControllerAction` to `Cuprum::Rails::Controllers::Action`.
|
41
|
+
|
42
|
+
- **(Breaking Change)** Controller actions now require a `:controller` argument when called.
|
43
|
+
|
44
|
+
#### Middleware
|
45
|
+
|
46
|
+
Implemented controller middleware.
|
47
|
+
|
48
|
+
- `Cuprum::Rails::Controllers::Middleware`.
|
49
|
+
- `Cuprum::Rails::Controllers::ClassMethods::Middleware`.
|
50
|
+
|
51
|
+
Updated `Cuprum::Rails::Controllers::Action` to apply configured middleware.
|
52
|
+
|
53
|
+
#### Requests
|
54
|
+
|
55
|
+
Added `#context` method to access the original request controller or context.
|
56
|
+
|
57
|
+
Added `#member_action?` method to identify requests to resourceful member actions.
|
58
|
+
|
59
|
+
Added `#native_session` method to lazily access the native controller session.
|
60
|
+
|
61
|
+
Added `#properties` method to access all request properties as a Hash.
|
62
|
+
|
63
|
+
Added `#path_params` method and properly handle parameters from the request path.
|
64
|
+
|
65
|
+
**(Breaking Change)** Renamed `#method` property to `#http_method`.
|
66
|
+
|
67
|
+
#### Resources
|
68
|
+
|
69
|
+
Automatically generate a `Cuprum::Rails::Collection` when creating a resource with a `record_class` but no explicit `collection`.
|
70
|
+
|
71
|
+
Added `#actions` option, which is automatically generated for singular and plural resources.
|
72
|
+
|
73
|
+
Added `#parent` option and associated `#ancestors` and `#each_ancestors` methods.
|
74
|
+
|
75
|
+
- **(Breaking Change)** Removed `Resource#collection`.
|
76
|
+
|
77
|
+
#### Responders
|
78
|
+
|
79
|
+
Implemented `Responders::Html::Resource` to handle both singular and plural resources.
|
80
|
+
|
81
|
+
- `Cuprum::Rails::Responders::Html::PluralResource` is now deprecated.
|
82
|
+
- `Cuprum::Rails::Responders::Html::SingularResource` is now deprecated.
|
83
|
+
|
84
|
+
Updated `JsonResponder` to display full error messages in the development environment.
|
85
|
+
|
86
|
+
Extracted `Responders::BaseResponder`.
|
87
|
+
|
88
|
+
Extracted `Responders::Html::Rendering`.
|
89
|
+
|
90
|
+
**(Breaking Change)** Responders now require `:controller` and `:request` parameters on initialization.
|
91
|
+
|
92
|
+
#### Responses
|
93
|
+
|
94
|
+
Implemented `Responses::HeadResponse`.
|
95
|
+
|
96
|
+
Implemented `Responses::Html::RedirectBackResponse`.
|
97
|
+
|
98
|
+
Added Rails flash message support to HTML responses:
|
99
|
+
|
100
|
+
- `Responses::Html::RedirectBackResponse`.
|
101
|
+
- `Responses::Html::RedirectResponse`.
|
102
|
+
- `Responses::Html::RenderResponse`.
|
103
|
+
|
104
|
+
### Results
|
105
|
+
|
106
|
+
Implemented `Cuprum::Rails::Result`, which includes a `#metadata` property for passing contextual data such as an authentication session or page configuration.
|
107
|
+
|
108
|
+
### Routes
|
109
|
+
|
110
|
+
Route helpers not accept a wildcards hash for populating route wildcards, as an alternative to calling `routes.with_wildcards`.
|
111
|
+
|
112
|
+
Member route methods now accept a primary key value as well as an entity, or allow the key to be passed as part of the wildcards.
|
113
|
+
|
114
|
+
### RSpec
|
115
|
+
|
116
|
+
Implemented contracts for Cuprum::Rails actions:
|
117
|
+
|
118
|
+
- `Cuprum::Rails::RSpec::Contracts::Actions::CreateContracts`
|
119
|
+
- `Cuprum::Rails::RSpec::Contracts::Actions::DestroyContracts`
|
120
|
+
- `Cuprum::Rails::RSpec::Contracts::Actions::EditContracts`
|
121
|
+
- `Cuprum::Rails::RSpec::Contracts::Actions::IndexContracts`
|
122
|
+
- `Cuprum::Rails::RSpec::Contracts::Actions::NewContracts`
|
123
|
+
- `Cuprum::Rails::RSpec::Contracts::Actions::ShowContracts`
|
124
|
+
- `Cuprum::Rails::RSpec::Contracts::Actions::UpdateContracts`
|
125
|
+
|
126
|
+
Contracts allow libraries or applications to verify their actions implement the action specifications.
|
127
|
+
|
128
|
+
Defined `Cuprum::Rails::RSpec::Contracts::SerializersContracts`:
|
129
|
+
|
130
|
+
- `ShouldSerailizeAttributesContract`: Verifies that the specified attributes are serialized with the expected values.
|
131
|
+
|
132
|
+
Implemented `Cuprum::Rails::RSpec::Matchers::BeAResultMatcher`, which adds support for a `#metadata` property to the `be_a_result` matcher.
|
133
|
+
|
134
|
+
- **(Breaking Change)** Existing contracts were moved into the `Cuprum::Rails::RSpec::Contracts` namespace and are scoped by type.
|
135
|
+
- `COMMAND_CONTRACT` is now `Contracts::CommandContracts::ShouldBeARailsCommandContract`.
|
136
|
+
- `DEFINE_ROUTE_CONTRACT` is replaced with `Contracts::RoutesContracts::ShouldDefineCollectionRouteContract` and `ShouldDefineMemberRouteContract`.
|
137
|
+
|
138
|
+
### Serializers
|
139
|
+
|
140
|
+
Implemented `Cuprum::Rails::Serializers::Context`.
|
141
|
+
|
142
|
+
- Refactored serializers to take a `context:` keyword instead of `serializers:`.
|
143
|
+
|
144
|
+
Implemented `Cuprum::Rails::Serializers::Json::PropertiesSerializer`.
|
145
|
+
|
146
|
+
- Refactored `AttributesSerializer` to inherit from `PropertiesSerializer`. This is a breaking change for certain serializers with a block passed to `.attribute`.
|
147
|
+
|
3
148
|
## 0.1.0
|
4
149
|
|
5
150
|
Initial version.
|
data/DEVELOPMENT.md
CHANGED
@@ -4,6 +4,26 @@
|
|
4
4
|
|
5
5
|
- Remove ActionController::Parameters reference in Cuprum::Rails::Action.
|
6
6
|
|
7
|
+
Test cases:
|
8
|
+
|
9
|
+
- #create, #update (, #new ?) with generated attributes.
|
10
|
+
- #edit, #new with related resources
|
11
|
+
|
12
|
+
### Nested Resources
|
13
|
+
|
14
|
+
Interactions are optional - opt-in? With a DSL?
|
15
|
+
|
16
|
+
- With a required association (e.g. Chapter#book => /books/:book_id/chapters)
|
17
|
+
- All actions: require :book_id, valid Book entity, response 'book' => book
|
18
|
+
- With a singular association (e.g. Book#author => /books)
|
19
|
+
- #index: response 'books' => mapped books
|
20
|
+
- #new, #edit: response 'books' => all books
|
21
|
+
- #create, #show, #update, #destroy: response 'book' => mapped book
|
22
|
+
- With a plural association (e.g. Book#chapters)
|
23
|
+
- #create: create associated chapters, response 'chapters' => created chapters
|
24
|
+
- #show: response 'chapters' => mapped chapters
|
25
|
+
- #destroy: destroy associated chapters, response 'chapters' => destroyed chapters
|
26
|
+
|
7
27
|
## Controllers
|
8
28
|
|
9
29
|
- Different cases for controllers.
|