spec/extensions/structures_spec.rb in paradocs-1.1.3 vs spec/extensions/structures_spec.rb in paradocs-1.1.4

- old
+ new

@@ -16,11 +16,11 @@ let(:schema) do Paradocs::Schema.new do subschema(:highest_level) { field(:test).present } # no mutations on this level -> subschema ignored field(:data).type(:object).present.schema do - field(:id).type(:integer).present.policy(:policy_with_error) + field(:id).type(:integer).present.policy(:policy_with_error).as(:user_id) field(:name).type(:string).meta(label: "very important staff").description("Example description").example("John") field(:role).type(:string).declared.options(["admin", "user"]).default("user").mutates_schema! do |*| :test_subschema end field(:extra).type(:array).required.schema do @@ -62,17 +62,18 @@ _errors: [], _subschemes: {}, test_field: {required: true, present: true, json_path: "$.data.test_field", nested_name: "data.test_field"} } }) - expect(data_structure[:id]).to eq({ + expect(data_structure[:user_id]).to eq({ type: :integer, required: true, present: true, policy_with_error: {errors: [ArgumentError]}, - json_path: "$.data.id", - nested_name: "data.id" + alias: :user_id, + json_path: "$.data.user_id", + nested_name: "data.user_id" }) expect(data_structure[:name]).to eq({ type: :string, label: "very important staff", description: "Example description", @@ -129,15 +130,16 @@ "data.extra.extra" => { default: false, json_path: "$.data.extra[].extra", policy_with_silent_error: {errors: []} }, - "data.id" => { + "data.user_id" => { type: :integer, required: true, present: true, - json_path: "$.data.id", + alias: :user_id, + json_path: "$.data.user_id", policy_with_error: {errors: [ArgumentError]} }, "data.name" => { type: :string, json_path: "$.data.name", @@ -178,21 +180,21 @@ it "generates N structures, where N = number of unique combinations of applied subschemas" do expect(schema.structure.all_flatten).to eq({ subschema: { _errors: [ArgumentError], "data" => {type: :object, required: true, present: true, json_path: "$.data"}, - "data.id" => {type: :integer, required: true, present: true, policy_with_error: {errors: [ArgumentError]}, json_path: "$.data.id"}, + "data.user_id" => {type: :integer, required: true, present: true, policy_with_error: {errors: [ArgumentError]}, alias: :user_id, json_path: "$.data.user_id"}, "data.name" => {type: :string, label: "very important staff", json_path: "$.data.name", mutates_schema: true, description: "Example description", example: "John"}, "data.role" => {type: :string, options: ["admin", "user"], default: "user", json_path: "$.data.role", mutates_schema: true}, "data.extra" => {type: :array, required: true, json_path: "$.data.extra[]"}, "data.extra.extra" => {default: false, policy_with_silent_error: {errors: []}, json_path: "$.data.extra[].extra"}, "data.test_field" => {required: true, present: true, json_path: "$.data.test_field"} }, test_subschema: { _errors: [ArgumentError], "data" => {type: :object, required: true, present: true, json_path: "$.data"}, - "data.id" => {type: :integer, required: true, present: true, policy_with_error: {errors: [ArgumentError]}, json_path: "$.data.id"}, + "data.user_id" => {type: :integer, required: true, present: true, policy_with_error: {errors: [ArgumentError]}, alias: :user_id, json_path: "$.data.user_id"}, "data.name" => {type: :string, label: "very important staff", json_path: "$.data.name", mutates_schema: true, description: "Example description", example: "John"}, "data.role" => {type: :string, options: ["admin", "user"], default: "user", json_path: "$.data.role", mutates_schema: true}, "data.extra" => {type: :array, required: true, json_path: "$.data.extra[]"}, "data.extra.extra" => {default: false, policy_with_silent_error: {errors: []}, json_path: "$.data.extra[].extra"}, "data.test1" => {required: true, present: true, json_path: "$.data.test1"} @@ -213,11 +215,11 @@ json_path: "$.data", nested_name: "data", structure: { "role" => {type: :string, options: ["admin", "user"], default: "user", json_path: "$.data.role", nested_name: "data.role", mutates_schema: true}, "test_field" => {required: true, present: true, json_path: "$.data.test_field", nested_name: "data.test_field"}, - "id" => {type: :integer, required: true, present: true, policy_with_error: {errors: [ArgumentError]}, json_path: "$.data.id", nested_name: "data.id"}, + "user_id" => {type: :integer, required: true, present: true, policy_with_error: {errors: [ArgumentError]}, alias: :user_id, json_path: "$.data.user_id", nested_name: "data.user_id"}, "name" => {type: :string, label: "very important staff", json_path: "$.data.name", mutates_schema: true, nested_name: "data.name", description: "Example description", example: "John"}, "extra" => { type: :array, required: true, json_path: "$.data.extra[]", nested_name: "data.extra", structure: {"extra" => {default: false, policy_with_silent_error: {errors: []}, json_path: "$.data.extra[].extra", nested_name: "data.extra.extra"}} } @@ -231,14 +233,14 @@ required: true, present: true, json_path: "$.data", nested_name: "data", structure: { - "role" => {type: :string, options: ["admin", "user"], default: "user", json_path: "$.data.role", nested_name: "data.role", mutates_schema: true}, - "test1" => {required: true, present: true, json_path: "$.data.test1", nested_name: "data.test1"}, - "id" => {type: :integer, required: true, present: true, policy_with_error: {errors: [ArgumentError]}, json_path: "$.data.id", nested_name: "data.id"}, - "name" => {type: :string, label: "very important staff", json_path: "$.data.name", mutates_schema: true, nested_name: "data.name", description: "Example description", example: "John"}, - "extra" => { + "role" => {type: :string, options: ["admin", "user"], default: "user", json_path: "$.data.role", nested_name: "data.role", mutates_schema: true}, + "test1" => {required: true, present: true, json_path: "$.data.test1", nested_name: "data.test1"}, + "user_id" => {type: :integer, required: true, present: true, policy_with_error: {errors: [ArgumentError]}, alias: :user_id, json_path: "$.data.user_id", nested_name: "data.user_id"}, + "name" => {type: :string, label: "very important staff", json_path: "$.data.name", mutates_schema: true, nested_name: "data.name", description: "Example description", example: "John"}, + "extra" => { type: :array, required: true, json_path: "$.data.extra[]", nested_name: "data.extra", structure: {"extra" => {default: false, policy_with_silent_error: {errors: []}, json_path: "$.data.extra[].extra", nested_name: "data.extra.extra"}}} } } })