active_cached_resource 0.0.1.pre → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/LICENSE +21 -0
- data/lib/active_cached_resource/caching.rb +104 -1
- data/lib/active_cached_resource/configuration.rb +22 -1
- data/lib/active_cached_resource/logger.rb +14 -0
- data/lib/active_cached_resource/model.rb +18 -0
- data/lib/active_cached_resource/version.rb +1 -8
- data/lib/activeresource/lib/active_resource/collection.rb +14 -1
- data/lib/activeresource/lib/active_resource/railtie.rb +2 -2
- data/lib/activeresource/lib/active_resource.rb +1 -1
- metadata +5 -401
- data/.rspec +0 -3
- data/.rubocop.yml +0 -22
- data/.standard.yml +0 -2
- data/Rakefile +0 -21
- data/example/consumer/.dockerignore +0 -41
- data/example/consumer/.gitattributes +0 -9
- data/example/consumer/.gitignore +0 -36
- data/example/consumer/.kamal/hooks/docker-setup.sample +0 -3
- data/example/consumer/.kamal/hooks/post-deploy.sample +0 -14
- data/example/consumer/.kamal/hooks/post-proxy-reboot.sample +0 -3
- data/example/consumer/.kamal/hooks/pre-build.sample +0 -51
- data/example/consumer/.kamal/hooks/pre-connect.sample +0 -47
- data/example/consumer/.kamal/hooks/pre-deploy.sample +0 -109
- data/example/consumer/.kamal/hooks/pre-proxy-reboot.sample +0 -3
- data/example/consumer/.kamal/secrets +0 -17
- data/example/consumer/Dockerfile +0 -65
- data/example/consumer/Gemfile +0 -17
- data/example/consumer/Rakefile +0 -6
- data/example/consumer/app/controllers/application_controller.rb +0 -2
- data/example/consumer/app/controllers/concerns/.keep +0 -0
- data/example/consumer/app/jobs/application_job.rb +0 -7
- data/example/consumer/app/mailers/application_mailer.rb +0 -4
- data/example/consumer/app/models/application_record.rb +0 -3
- data/example/consumer/app/models/concerns/.keep +0 -0
- data/example/consumer/app/models/person.rb +0 -9
- data/example/consumer/app/views/layouts/mailer.html.erb +0 -13
- data/example/consumer/app/views/layouts/mailer.text.erb +0 -1
- data/example/consumer/bin/brakeman +0 -7
- data/example/consumer/bin/bundle +0 -109
- data/example/consumer/bin/dev +0 -2
- data/example/consumer/bin/docker-entrypoint +0 -14
- data/example/consumer/bin/jobs +0 -6
- data/example/consumer/bin/kamal +0 -27
- data/example/consumer/bin/rails +0 -4
- data/example/consumer/bin/rake +0 -4
- data/example/consumer/bin/rubocop +0 -8
- data/example/consumer/bin/setup +0 -34
- data/example/consumer/bin/thrust +0 -5
- data/example/consumer/config/application.rb +0 -20
- data/example/consumer/config/boot.rb +0 -3
- data/example/consumer/config/cache.yml +0 -16
- data/example/consumer/config/credentials.yml.enc +0 -1
- data/example/consumer/config/database.yml +0 -14
- data/example/consumer/config/deploy.yml +0 -116
- data/example/consumer/config/environment.rb +0 -5
- data/example/consumer/config/environments/development.rb +0 -64
- data/example/consumer/config/environments/production.rb +0 -85
- data/example/consumer/config/environments/test.rb +0 -50
- data/example/consumer/config/initializers/cors.rb +0 -16
- data/example/consumer/config/initializers/filter_parameter_logging.rb +0 -8
- data/example/consumer/config/initializers/inflections.rb +0 -16
- data/example/consumer/config/locales/en.yml +0 -31
- data/example/consumer/config/puma.rb +0 -41
- data/example/consumer/config/queue.yml +0 -18
- data/example/consumer/config/recurring.yml +0 -10
- data/example/consumer/config/routes.rb +0 -10
- data/example/consumer/config.ru +0 -6
- data/example/consumer/db/cache_schema.rb +0 -14
- data/example/consumer/db/queue_schema.rb +0 -129
- data/example/consumer/db/seeds.rb +0 -0
- data/example/consumer/lib/tasks/.keep +0 -0
- data/example/consumer/log/.keep +0 -0
- data/example/consumer/public/robots.txt +0 -1
- data/example/consumer/script/.keep +0 -0
- data/example/consumer/storage/.keep +0 -0
- data/example/consumer/tmp/.keep +0 -0
- data/example/consumer/tmp/cache/.keep +0 -0
- data/example/consumer/tmp/pids/.keep +0 -0
- data/example/consumer/tmp/storage/.keep +0 -0
- data/example/consumer/vendor/.keep +0 -0
- data/example/provider/.dockerignore +0 -41
- data/example/provider/.gitattributes +0 -9
- data/example/provider/.gitignore +0 -32
- data/example/provider/.kamal/hooks/docker-setup.sample +0 -3
- data/example/provider/.kamal/hooks/post-deploy.sample +0 -14
- data/example/provider/.kamal/hooks/post-proxy-reboot.sample +0 -3
- data/example/provider/.kamal/hooks/pre-build.sample +0 -51
- data/example/provider/.kamal/hooks/pre-connect.sample +0 -47
- data/example/provider/.kamal/hooks/pre-deploy.sample +0 -109
- data/example/provider/.kamal/hooks/pre-proxy-reboot.sample +0 -3
- data/example/provider/.kamal/secrets +0 -17
- data/example/provider/Dockerfile +0 -65
- data/example/provider/Gemfile +0 -14
- data/example/provider/Rakefile +0 -6
- data/example/provider/app/controllers/application_controller.rb +0 -2
- data/example/provider/app/controllers/concerns/.keep +0 -0
- data/example/provider/app/controllers/people_controller.rb +0 -68
- data/example/provider/app/jobs/application_job.rb +0 -7
- data/example/provider/app/mailers/application_mailer.rb +0 -4
- data/example/provider/app/models/address.rb +0 -3
- data/example/provider/app/models/application_record.rb +0 -3
- data/example/provider/app/models/company.rb +0 -3
- data/example/provider/app/models/concerns/.keep +0 -0
- data/example/provider/app/models/person.rb +0 -6
- data/example/provider/app/views/layouts/mailer.html.erb +0 -13
- data/example/provider/app/views/layouts/mailer.text.erb +0 -1
- data/example/provider/bin/brakeman +0 -7
- data/example/provider/bin/bundle +0 -109
- data/example/provider/bin/dev +0 -2
- data/example/provider/bin/docker-entrypoint +0 -14
- data/example/provider/bin/jobs +0 -6
- data/example/provider/bin/kamal +0 -27
- data/example/provider/bin/rails +0 -4
- data/example/provider/bin/rake +0 -4
- data/example/provider/bin/rubocop +0 -8
- data/example/provider/bin/setup +0 -34
- data/example/provider/bin/thrust +0 -5
- data/example/provider/config/application.rb +0 -44
- data/example/provider/config/boot.rb +0 -3
- data/example/provider/config/cache.yml +0 -16
- data/example/provider/config/credentials.yml.enc +0 -1
- data/example/provider/config/database.yml +0 -20
- data/example/provider/config/deploy.yml +0 -116
- data/example/provider/config/environment.rb +0 -5
- data/example/provider/config/environments/development.rb +0 -64
- data/example/provider/config/environments/production.rb +0 -85
- data/example/provider/config/environments/test.rb +0 -50
- data/example/provider/config/initializers/cors.rb +0 -16
- data/example/provider/config/initializers/filter_parameter_logging.rb +0 -8
- data/example/provider/config/initializers/inflections.rb +0 -16
- data/example/provider/config/locales/en.yml +0 -31
- data/example/provider/config/puma.rb +0 -41
- data/example/provider/config/queue.yml +0 -18
- data/example/provider/config/recurring.yml +0 -10
- data/example/provider/config/routes.rb +0 -4
- data/example/provider/config.ru +0 -6
- data/example/provider/db/cache_schema.rb +0 -14
- data/example/provider/db/migrate/20241202183937_create_people.rb +0 -11
- data/example/provider/db/migrate/20241202183955_create_addresses.rb +0 -13
- data/example/provider/db/migrate/20241202184017_create_companies.rb +0 -14
- data/example/provider/db/queue_schema.rb +0 -129
- data/example/provider/db/schema.rb +0 -47
- data/example/provider/db/seeds.rb +0 -18
- data/example/provider/lib/tasks/.keep +0 -0
- data/example/provider/log/.keep +0 -0
- data/example/provider/public/robots.txt +0 -1
- data/example/provider/script/.keep +0 -0
- data/example/provider/storage/.keep +0 -0
- data/example/provider/tmp/.keep +0 -0
- data/example/provider/tmp/pids/.keep +0 -0
- data/example/provider/tmp/storage/.keep +0 -0
- data/example/provider/vendor/.keep +0 -0
- data/lib/activeresource/.gitignore +0 -15
- data/lib/activeresource/examples/performance.rb +0 -72
- data/lib/activeresource/test/abstract_unit.rb +0 -153
- data/lib/activeresource/test/cases/active_job_serializer_test.rb +0 -53
- data/lib/activeresource/test/cases/association_test.rb +0 -104
- data/lib/activeresource/test/cases/associations/builder/belongs_to_test.rb +0 -42
- data/lib/activeresource/test/cases/associations/builder/has_many_test.rb +0 -28
- data/lib/activeresource/test/cases/associations/builder/has_one_test.rb +0 -28
- data/lib/activeresource/test/cases/authorization_test.rb +0 -276
- data/lib/activeresource/test/cases/base/custom_methods_test.rb +0 -155
- data/lib/activeresource/test/cases/base/equality_test.rb +0 -53
- data/lib/activeresource/test/cases/base/load_test.rb +0 -249
- data/lib/activeresource/test/cases/base/schema_test.rb +0 -428
- data/lib/activeresource/test/cases/base_errors_test.rb +0 -129
- data/lib/activeresource/test/cases/base_test.rb +0 -1622
- data/lib/activeresource/test/cases/callbacks_test.rb +0 -155
- data/lib/activeresource/test/cases/collection_test.rb +0 -172
- data/lib/activeresource/test/cases/connection_test.rb +0 -357
- data/lib/activeresource/test/cases/finder_test.rb +0 -217
- data/lib/activeresource/test/cases/format_test.rb +0 -137
- data/lib/activeresource/test/cases/http_mock_test.rb +0 -213
- data/lib/activeresource/test/cases/inheritence_test.rb +0 -19
- data/lib/activeresource/test/cases/inheriting_hash_test.rb +0 -25
- data/lib/activeresource/test/cases/log_subscriber_test.rb +0 -63
- data/lib/activeresource/test/cases/reflection_test.rb +0 -65
- data/lib/activeresource/test/cases/validations_test.rb +0 -78
- data/lib/activeresource/test/fixtures/address.rb +0 -20
- data/lib/activeresource/test/fixtures/beast.rb +0 -16
- data/lib/activeresource/test/fixtures/comment.rb +0 -5
- data/lib/activeresource/test/fixtures/customer.rb +0 -5
- data/lib/activeresource/test/fixtures/inventory.rb +0 -14
- data/lib/activeresource/test/fixtures/person.rb +0 -15
- data/lib/activeresource/test/fixtures/pet.rb +0 -6
- data/lib/activeresource/test/fixtures/post.rb +0 -5
- data/lib/activeresource/test/fixtures/product.rb +0 -11
- data/lib/activeresource/test/fixtures/project.rb +0 -19
- data/lib/activeresource/test/fixtures/proxy.rb +0 -6
- data/lib/activeresource/test/fixtures/sound.rb +0 -11
- data/lib/activeresource/test/fixtures/street_address.rb +0 -6
- data/lib/activeresource/test/fixtures/subscription_plan.rb +0 -7
- data/lib/activeresource/test/fixtures/weather.rb +0 -21
- data/lib/activeresource/test/setter_trap.rb +0 -28
- data/lib/activeresource/test/singleton_test.rb +0 -138
- data/lib/activeresource/test/threadsafe_attributes_test.rb +0 -91
- data/sorbet/config +0 -4
- data/sorbet/rbi/annotations/.gitattributes +0 -1
- data/sorbet/rbi/annotations/activemodel.rbi +0 -89
- data/sorbet/rbi/annotations/activesupport.rbi +0 -457
- data/sorbet/rbi/annotations/minitest.rbi +0 -119
- data/sorbet/rbi/annotations/rainbow.rbi +0 -269
- data/sorbet/rbi/dsl/.gitattributes +0 -1
- data/sorbet/rbi/dsl/active_support/callbacks.rbi +0 -21
- data/sorbet/rbi/gems/.gitattributes +0 -1
- data/sorbet/rbi/gems/actioncable@8.0.0.rbi +0 -252
- data/sorbet/rbi/gems/actionmailbox@8.0.0.rbi +0 -9
- data/sorbet/rbi/gems/actionmailer@8.0.0.rbi +0 -9
- data/sorbet/rbi/gems/actionpack@8.0.0.rbi +0 -20909
- data/sorbet/rbi/gems/actiontext@8.0.0.rbi +0 -9
- data/sorbet/rbi/gems/actionview@8.0.0.rbi +0 -16207
- data/sorbet/rbi/gems/activejob@8.0.0.rbi +0 -9
- data/sorbet/rbi/gems/activemodel-serializers-xml@1.0.3.rbi +0 -166
- data/sorbet/rbi/gems/activemodel@8.0.0.rbi +0 -6857
- data/sorbet/rbi/gems/activerecord@8.0.0.rbi +0 -42896
- data/sorbet/rbi/gems/activeresource@6.1.4.rbi +0 -3944
- data/sorbet/rbi/gems/activestorage@8.0.0.rbi +0 -9
- data/sorbet/rbi/gems/activesupport@8.0.0.rbi +0 -21251
- data/sorbet/rbi/gems/ast@2.4.2.rbi +0 -585
- data/sorbet/rbi/gems/base64@0.2.0.rbi +0 -509
- data/sorbet/rbi/gems/benchmark@0.4.0.rbi +0 -618
- data/sorbet/rbi/gems/bigdecimal@3.1.8.rbi +0 -78
- data/sorbet/rbi/gems/builder@3.3.0.rbi +0 -9
- data/sorbet/rbi/gems/bump@0.10.0.rbi +0 -169
- data/sorbet/rbi/gems/byebug@11.1.3.rbi +0 -3607
- data/sorbet/rbi/gems/coderay@1.1.3.rbi +0 -3427
- data/sorbet/rbi/gems/concurrent-ruby@1.3.4.rbi +0 -11645
- data/sorbet/rbi/gems/connection_pool@2.4.1.rbi +0 -9
- data/sorbet/rbi/gems/crass@1.0.6.rbi +0 -623
- data/sorbet/rbi/gems/date@3.4.0.rbi +0 -75
- data/sorbet/rbi/gems/diff-lcs@1.5.1.rbi +0 -1131
- data/sorbet/rbi/gems/docile@1.4.1.rbi +0 -377
- data/sorbet/rbi/gems/drb@2.2.1.rbi +0 -1347
- data/sorbet/rbi/gems/erubi@1.13.0.rbi +0 -150
- data/sorbet/rbi/gems/globalid@1.2.1.rbi +0 -9
- data/sorbet/rbi/gems/i18n@1.14.6.rbi +0 -2359
- data/sorbet/rbi/gems/io-console@0.7.2.rbi +0 -9
- data/sorbet/rbi/gems/json@2.8.2.rbi +0 -1901
- data/sorbet/rbi/gems/language_server-protocol@3.17.0.3.rbi +0 -14238
- data/sorbet/rbi/gems/lint_roller@1.1.0.rbi +0 -240
- data/sorbet/rbi/gems/logger@1.6.1.rbi +0 -920
- data/sorbet/rbi/gems/loofah@2.23.1.rbi +0 -1081
- data/sorbet/rbi/gems/mail@2.8.1.rbi +0 -9
- data/sorbet/rbi/gems/marcel@1.0.4.rbi +0 -9
- data/sorbet/rbi/gems/method_source@1.1.0.rbi +0 -304
- data/sorbet/rbi/gems/mini_mime@1.1.5.rbi +0 -9
- data/sorbet/rbi/gems/minitest@5.25.2.rbi +0 -1547
- data/sorbet/rbi/gems/net-imap@0.5.1.rbi +0 -9
- data/sorbet/rbi/gems/net-pop@0.1.2.rbi +0 -9
- data/sorbet/rbi/gems/net-protocol@0.2.2.rbi +0 -292
- data/sorbet/rbi/gems/net-smtp@0.5.0.rbi +0 -9
- data/sorbet/rbi/gems/netrc@0.11.0.rbi +0 -159
- data/sorbet/rbi/gems/nio4r@2.7.4.rbi +0 -9
- data/sorbet/rbi/gems/nokogiri@1.16.7.rbi +0 -7311
- data/sorbet/rbi/gems/parallel@1.26.3.rbi +0 -291
- data/sorbet/rbi/gems/parser@3.3.6.0.rbi +0 -5519
- data/sorbet/rbi/gems/prism@1.2.0.rbi +0 -39085
- data/sorbet/rbi/gems/pry-byebug@3.10.1.rbi +0 -1151
- data/sorbet/rbi/gems/pry@0.14.2.rbi +0 -10076
- data/sorbet/rbi/gems/psych@5.2.0.rbi +0 -1785
- data/sorbet/rbi/gems/racc@1.8.1.rbi +0 -162
- data/sorbet/rbi/gems/rack-session@2.0.0.rbi +0 -727
- data/sorbet/rbi/gems/rack-test@2.1.0.rbi +0 -747
- data/sorbet/rbi/gems/rack@3.1.8.rbi +0 -4905
- data/sorbet/rbi/gems/rackup@2.2.1.rbi +0 -230
- data/sorbet/rbi/gems/rails-dom-testing@2.2.0.rbi +0 -758
- data/sorbet/rbi/gems/rails-html-sanitizer@1.6.0.rbi +0 -785
- data/sorbet/rbi/gems/rails@8.0.0.rbi +0 -9
- data/sorbet/rbi/gems/railties@8.0.0.rbi +0 -6287
- data/sorbet/rbi/gems/rainbow@3.1.1.rbi +0 -403
- data/sorbet/rbi/gems/rake@13.2.1.rbi +0 -3091
- data/sorbet/rbi/gems/rbi@0.2.1.rbi +0 -4535
- data/sorbet/rbi/gems/rdoc@6.8.1.rbi +0 -12572
- data/sorbet/rbi/gems/regexp_parser@2.9.2.rbi +0 -3772
- data/sorbet/rbi/gems/reline@0.5.12.rbi +0 -2416
- data/sorbet/rbi/gems/rexml@3.3.9.rbi +0 -4858
- data/sorbet/rbi/gems/rspec-core@3.13.2.rbi +0 -11287
- data/sorbet/rbi/gems/rspec-expectations@3.13.3.rbi +0 -8183
- data/sorbet/rbi/gems/rspec-mocks@3.13.2.rbi +0 -5341
- data/sorbet/rbi/gems/rspec-support@3.13.1.rbi +0 -1630
- data/sorbet/rbi/gems/rspec@3.13.0.rbi +0 -83
- data/sorbet/rbi/gems/rubocop-ast@1.36.1.rbi +0 -7303
- data/sorbet/rbi/gems/rubocop-performance@1.21.1.rbi +0 -9
- data/sorbet/rbi/gems/rubocop@1.65.1.rbi +0 -58170
- data/sorbet/rbi/gems/ruby-progressbar@1.13.0.rbi +0 -1318
- data/sorbet/rbi/gems/securerandom@0.3.2.rbi +0 -395
- data/sorbet/rbi/gems/simplecov-html@0.13.1.rbi +0 -225
- data/sorbet/rbi/gems/simplecov@0.22.0.rbi +0 -2149
- data/sorbet/rbi/gems/simplecov_json_formatter@0.1.4.rbi +0 -9
- data/sorbet/rbi/gems/spoom@1.5.0.rbi +0 -4932
- data/sorbet/rbi/gems/standard-custom@1.0.2.rbi +0 -9
- data/sorbet/rbi/gems/standard-performance@1.4.0.rbi +0 -9
- data/sorbet/rbi/gems/standard@1.40.0.rbi +0 -929
- data/sorbet/rbi/gems/stringio@3.1.2.rbi +0 -9
- data/sorbet/rbi/gems/tapioca@0.16.4.rbi +0 -3597
- data/sorbet/rbi/gems/thor@1.3.2.rbi +0 -4378
- data/sorbet/rbi/gems/timeout@0.4.2.rbi +0 -151
- data/sorbet/rbi/gems/tzinfo@2.0.6.rbi +0 -5918
- data/sorbet/rbi/gems/unicode-display_width@2.6.0.rbi +0 -66
- data/sorbet/rbi/gems/uri@1.0.2.rbi +0 -2377
- data/sorbet/rbi/gems/useragent@0.16.10.rbi +0 -9
- data/sorbet/rbi/gems/websocket-driver@0.7.6.rbi +0 -9
- data/sorbet/rbi/gems/websocket-extensions@0.1.5.rbi +0 -9
- data/sorbet/rbi/gems/yard-sorbet@0.9.0.rbi +0 -435
- data/sorbet/rbi/gems/yard@0.9.37.rbi +0 -18504
- data/sorbet/rbi/gems/zeitwerk@2.7.1.rbi +0 -9
- data/sorbet/tapioca/config.yml +0 -13
- data/sorbet/tapioca/require.rb +0 -12
@@ -1,428 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "abstract_unit"
|
4
|
-
require "active_support/core_ext/hash/conversions"
|
5
|
-
require "fixtures/person"
|
6
|
-
require "fixtures/street_address"
|
7
|
-
|
8
|
-
########################################################################
|
9
|
-
# Testing the schema of your Active Resource models
|
10
|
-
########################################################################
|
11
|
-
class SchemaTest < ActiveSupport::TestCase
|
12
|
-
def setup
|
13
|
-
setup_response # find me in abstract_unit
|
14
|
-
end
|
15
|
-
|
16
|
-
def teardown
|
17
|
-
Person.schema = nil # hack to stop test bleedthrough...
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
#####################################################
|
22
|
-
# Passing in a schema directly and returning it
|
23
|
-
####
|
24
|
-
|
25
|
-
test "schema on a new model should be empty" do
|
26
|
-
assert Person.schema.blank?, "should have a blank class schema"
|
27
|
-
assert Person.new.schema.blank?, "should have a blank instance schema"
|
28
|
-
end
|
29
|
-
|
30
|
-
test "schema should only accept a hash" do
|
31
|
-
["blahblah", ["one", "two"], [:age, :name], Person.new].each do |bad_schema|
|
32
|
-
assert_raises(ArgumentError, "should only accept a hash (or nil), but accepted: #{bad_schema.inspect}") do
|
33
|
-
Person.schema = bad_schema
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
test "schema should accept a simple hash" do
|
39
|
-
new_schema = { "age" => "integer", "name" => "string",
|
40
|
-
"height" => "float", "bio" => "text",
|
41
|
-
"weight" => "decimal", "photo" => "binary",
|
42
|
-
"alive" => "boolean", "created_at" => "timestamp",
|
43
|
-
"thetime" => "time", "thedate" => "date", "mydatetime" => "datetime" }
|
44
|
-
|
45
|
-
assert_nothing_raised { Person.schema = new_schema }
|
46
|
-
assert_equal new_schema, Person.schema
|
47
|
-
end
|
48
|
-
|
49
|
-
test "schema should accept a hash with simple values" do
|
50
|
-
new_schema = { "age" => "integer", "name" => "string",
|
51
|
-
"height" => "float", "bio" => "text",
|
52
|
-
"weight" => "decimal", "photo" => "binary",
|
53
|
-
"alive" => "boolean", "created_at" => "timestamp",
|
54
|
-
"thetime" => "time", "thedate" => "date", "mydatetime" => "datetime" }
|
55
|
-
|
56
|
-
assert_nothing_raised { Person.schema = new_schema }
|
57
|
-
assert_equal new_schema, Person.schema
|
58
|
-
end
|
59
|
-
|
60
|
-
test "schema should accept all known attribute types as values" do
|
61
|
-
ActiveResource::Schema::KNOWN_ATTRIBUTE_TYPES.each do |the_type|
|
62
|
-
assert_nothing_raised { Person.schema = { "my_key" => the_type } }
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
test "schema should not accept unknown values" do
|
67
|
-
bad_values = [ :oogle, :blob, "thing"]
|
68
|
-
|
69
|
-
bad_values.each do |bad_value|
|
70
|
-
assert_raises(ArgumentError, "should only accept a known attribute type, but accepted: #{bad_value.inspect}") do
|
71
|
-
Person.schema = { "key" => bad_value }
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
test "schema should accept nil and remove the schema" do
|
77
|
-
new_schema = { "age" => "integer", "name" => "string",
|
78
|
-
"height" => "float", "bio" => "text",
|
79
|
-
"weight" => "decimal", "photo" => "binary",
|
80
|
-
"alive" => "boolean", "created_at" => "timestamp",
|
81
|
-
"thetime" => "time", "thedate" => "date", "mydatetime" => "datetime" }
|
82
|
-
|
83
|
-
assert_nothing_raised { Person.schema = new_schema }
|
84
|
-
assert_equal new_schema, Person.schema # sanity check
|
85
|
-
|
86
|
-
assert_nothing_raised { Person.schema = nil }
|
87
|
-
assert_nil Person.schema, "should have nulled out the schema, but still had: #{Person.schema.inspect}"
|
88
|
-
end
|
89
|
-
|
90
|
-
test "schema should be with indifferent access" do
|
91
|
-
new_schema = { "age" => "integer", "name" => "string",
|
92
|
-
"height" => "float", "bio" => "text",
|
93
|
-
"weight" => "decimal", "photo" => "binary",
|
94
|
-
"alive" => "boolean", "created_at" => "timestamp",
|
95
|
-
"thetime" => "time", "thedate" => "date", "mydatetime" => "datetime" }
|
96
|
-
|
97
|
-
new_schema_syms = new_schema.keys
|
98
|
-
|
99
|
-
assert_nothing_raised { Person.schema = new_schema }
|
100
|
-
new_schema_syms.each do |col|
|
101
|
-
assert Person.new.respond_to?(col.to_s), "should respond to the schema's string key, but failed on: #{col}"
|
102
|
-
assert Person.new.respond_to?(col.to_sym), "should respond to the schema's symbol key, but failed on: #{col.to_sym}"
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
test "schema on a fetched resource should return all the attributes of that model instance" do
|
107
|
-
p = Person.find(1)
|
108
|
-
s = p.schema
|
109
|
-
|
110
|
-
assert s.present?, "should have found a non-empty schema!"
|
111
|
-
|
112
|
-
p.attributes.each do |the_attr, val|
|
113
|
-
assert s.has_key?(the_attr), "should have found attr: #{the_attr} in schema, but only had: #{s.inspect}"
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
test "with two instances, default schema should match the attributes of the individual instances - even if they differ" do
|
118
|
-
matz = Person.find(1)
|
119
|
-
rick = Person.find(6)
|
120
|
-
|
121
|
-
m_attrs = matz.attributes.keys.sort
|
122
|
-
r_attrs = rick.attributes.keys.sort
|
123
|
-
|
124
|
-
assert_not_equal m_attrs, r_attrs, "should have different attributes on each model"
|
125
|
-
|
126
|
-
assert_not_equal matz.schema, rick.schema, "should have had different schemas too"
|
127
|
-
end
|
128
|
-
|
129
|
-
test "defining a schema should return it when asked" do
|
130
|
-
assert Person.schema.blank?, "should have a blank class schema"
|
131
|
-
new_schema = { "age" => "integer", "name" => "string",
|
132
|
-
"height" => "float", "bio" => "text",
|
133
|
-
"weight" => "decimal", "photo" => "binary",
|
134
|
-
"alive" => "boolean", "created_at" => "timestamp",
|
135
|
-
"thetime" => "time", "thedate" => "date", "mydatetime" => "datetime" }
|
136
|
-
|
137
|
-
assert_nothing_raised {
|
138
|
-
Person.schema = new_schema
|
139
|
-
assert_equal new_schema, Person.schema, "should have saved the schema on the class"
|
140
|
-
assert_equal new_schema, Person.new.schema, "should have made the schema available to every instance"
|
141
|
-
}
|
142
|
-
end
|
143
|
-
|
144
|
-
test "defining a schema, then fetching a model should still match the defined schema" do
|
145
|
-
# sanity checks
|
146
|
-
assert Person.schema.blank?, "should have a blank class schema"
|
147
|
-
new_schema = { "age" => "integer", "name" => "string",
|
148
|
-
"height" => "float", "bio" => "text",
|
149
|
-
"weight" => "decimal", "photo" => "binary",
|
150
|
-
"alive" => "boolean", "created_at" => "timestamp",
|
151
|
-
"thetime" => "time", "thedate" => "date", "mydatetime" => "datetime" }
|
152
|
-
|
153
|
-
matz = Person.find(1)
|
154
|
-
assert_not matz.schema.blank?, "should have some sort of schema on an instance variable"
|
155
|
-
assert_not_equal new_schema, matz.schema, "should not have the class-level schema until it's been added to the class!"
|
156
|
-
|
157
|
-
assert_nothing_raised {
|
158
|
-
Person.schema = new_schema
|
159
|
-
assert_equal new_schema, matz.schema, "class-level schema should override instance-level schema"
|
160
|
-
}
|
161
|
-
end
|
162
|
-
|
163
|
-
|
164
|
-
#####################################################
|
165
|
-
# Using the schema syntax
|
166
|
-
####
|
167
|
-
|
168
|
-
test "should be able to use schema" do
|
169
|
-
assert_respond_to Person, :schema, "should at least respond to the schema method"
|
170
|
-
|
171
|
-
assert_nothing_raised do
|
172
|
-
Person.schema { }
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
test "schema definition should store and return attribute set" do
|
177
|
-
assert_nothing_raised do
|
178
|
-
s = nil
|
179
|
-
Person.schema do
|
180
|
-
s = self
|
181
|
-
attribute :foo, :string
|
182
|
-
end
|
183
|
-
assert_respond_to s, :attrs, "should return attributes in theory"
|
184
|
-
assert_equal({ "foo" => "string" }, s.attrs, "should return attributes in practice")
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
test "should be able to add attributes through schema" do
|
189
|
-
assert_nothing_raised do
|
190
|
-
s = nil
|
191
|
-
Person.schema do
|
192
|
-
s = self
|
193
|
-
attribute("foo", "string")
|
194
|
-
end
|
195
|
-
assert s.attrs.has_key?("foo"), "should have saved the attribute name"
|
196
|
-
assert_equal "string", s.attrs["foo"], "should have saved the attribute type"
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
test "should convert symbol attributes to strings" do
|
201
|
-
assert_nothing_raised do
|
202
|
-
s = nil
|
203
|
-
Person.schema do
|
204
|
-
s = self
|
205
|
-
attribute(:foo, :integer)
|
206
|
-
end
|
207
|
-
|
208
|
-
assert s.attrs.has_key?("foo"), "should have saved the attribute name as a string"
|
209
|
-
assert_equal "integer", s.attrs["foo"], "should have saved the attribute type as a string"
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
test "should be able to add all known attribute types" do
|
214
|
-
assert_nothing_raised do
|
215
|
-
ActiveResource::Schema::KNOWN_ATTRIBUTE_TYPES.each do |the_type|
|
216
|
-
s = nil
|
217
|
-
Person.schema do
|
218
|
-
s = self
|
219
|
-
attribute("foo", the_type)
|
220
|
-
end
|
221
|
-
assert s.attrs.has_key?("foo"), "should have saved the attribute name"
|
222
|
-
assert_equal the_type.to_s, s.attrs["foo"], "should have saved the attribute type of: #{the_type}"
|
223
|
-
end
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
test "attributes should not accept unknown values" do
|
228
|
-
bad_values = [ :oogle, :blob, "thing"]
|
229
|
-
|
230
|
-
bad_values.each do |bad_value|
|
231
|
-
assert_raises(ArgumentError, "should only accept a known attribute type, but accepted: #{bad_value.inspect}") do
|
232
|
-
Person.schema do
|
233
|
-
attribute "key", bad_value
|
234
|
-
end
|
235
|
-
end
|
236
|
-
assert_not self.respond_to?(bad_value), "should only respond to a known attribute type, but accepted: #{bad_value.inspect}"
|
237
|
-
assert_raises(NoMethodError, "should only have methods for known attribute types, but accepted: #{bad_value.inspect}") do
|
238
|
-
Person.schema do
|
239
|
-
send bad_value, "key"
|
240
|
-
end
|
241
|
-
end
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
test "should accept attribute types as the type's name as the method" do
|
246
|
-
ActiveResource::Schema::KNOWN_ATTRIBUTE_TYPES.each do |the_type|
|
247
|
-
s = nil
|
248
|
-
Person.schema do
|
249
|
-
s = self
|
250
|
-
send(the_type, "foo")
|
251
|
-
end
|
252
|
-
assert s.attrs.has_key?("foo"), "should now have saved the attribute name"
|
253
|
-
assert_equal the_type.to_s, s.attrs["foo"], "should have saved the attribute type of: #{the_type}"
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
test "should accept multiple attribute names for an attribute method" do
|
258
|
-
names = ["foo", "bar", "baz"]
|
259
|
-
s = nil
|
260
|
-
Person.schema do
|
261
|
-
s = self
|
262
|
-
string(*names)
|
263
|
-
end
|
264
|
-
names.each do |the_name|
|
265
|
-
assert s.attrs.has_key?(the_name), "should now have saved the attribute name: #{the_name}"
|
266
|
-
assert_equal "string", s.attrs[the_name], "should have saved the attribute as a string"
|
267
|
-
end
|
268
|
-
end
|
269
|
-
|
270
|
-
|
271
|
-
#####################################################
|
272
|
-
# What a schema does for us
|
273
|
-
####
|
274
|
-
|
275
|
-
# respond_to_missing?
|
276
|
-
|
277
|
-
test "should respond positively to attributes that are only in the schema" do
|
278
|
-
new_attr_name = :my_new_schema_attribute
|
279
|
-
new_attr_name_two = :another_new_schema_attribute
|
280
|
-
assert Person.schema.blank?, "sanity check - should have a blank class schema"
|
281
|
-
|
282
|
-
assert_not Person.new.respond_to?(new_attr_name), "sanity check - should not respond to the brand-new attribute yet"
|
283
|
-
assert_not Person.new.respond_to?(new_attr_name_two), "sanity check - should not respond to the brand-new attribute yet"
|
284
|
-
|
285
|
-
assert_nothing_raised do
|
286
|
-
Person.schema = { new_attr_name.to_s => "string" }
|
287
|
-
Person.schema { string new_attr_name_two }
|
288
|
-
end
|
289
|
-
|
290
|
-
assert_respond_to Person.new, new_attr_name, "should respond to the attribute in a passed-in schema, but failed on: #{new_attr_name}"
|
291
|
-
assert_respond_to Person.new, new_attr_name_two, "should respond to the attribute from the schema, but failed on: #{new_attr_name_two}"
|
292
|
-
end
|
293
|
-
|
294
|
-
test "should not care about ordering of schema definitions" do
|
295
|
-
new_attr_name = :my_new_schema_attribute
|
296
|
-
new_attr_name_two = :another_new_schema_attribute
|
297
|
-
|
298
|
-
assert Person.schema.blank?, "sanity check - should have a blank class schema"
|
299
|
-
|
300
|
-
assert_not Person.new.respond_to?(new_attr_name), "sanity check - should not respond to the brand-new attribute yet"
|
301
|
-
assert_not Person.new.respond_to?(new_attr_name_two), "sanity check - should not respond to the brand-new attribute yet"
|
302
|
-
|
303
|
-
assert_nothing_raised do
|
304
|
-
Person.schema { string new_attr_name_two }
|
305
|
-
Person.schema = { new_attr_name.to_s => "string" }
|
306
|
-
end
|
307
|
-
|
308
|
-
assert_respond_to Person.new, new_attr_name, "should respond to the attribute in a passed-in schema, but failed on: #{new_attr_name}"
|
309
|
-
assert_respond_to Person.new, new_attr_name_two, "should respond to the attribute from the schema, but failed on: #{new_attr_name_two}"
|
310
|
-
end
|
311
|
-
|
312
|
-
test "should retrieve the `Method` object" do
|
313
|
-
new_attr_name = :my_new_schema_attribute
|
314
|
-
new_attr_name_two = :another_new_schema_attribute
|
315
|
-
assert Person.schema.blank?, "sanity check - should have a blank class schema"
|
316
|
-
|
317
|
-
assert_not Person.new.respond_to?(new_attr_name), "sanity check - should not respond to the brand-new attribute yet"
|
318
|
-
assert_not Person.new.respond_to?(new_attr_name_two), "sanity check - should not respond to the brand-new attribute yet"
|
319
|
-
|
320
|
-
assert_nothing_raised do
|
321
|
-
Person.schema = { new_attr_name.to_s => "string" }
|
322
|
-
Person.schema { string new_attr_name_two }
|
323
|
-
end
|
324
|
-
|
325
|
-
assert_instance_of Method, Person.new.method(new_attr_name)
|
326
|
-
assert_instance_of Method, Person.new.method(new_attr_name_two)
|
327
|
-
end
|
328
|
-
|
329
|
-
# method_missing effects
|
330
|
-
|
331
|
-
test "should not give method_missing for attribute only in schema" do
|
332
|
-
new_attr_name = :another_new_schema_attribute
|
333
|
-
new_attr_name_two = :another_new_schema_attribute
|
334
|
-
|
335
|
-
assert Person.schema.blank?, "sanity check - should have a blank class schema"
|
336
|
-
|
337
|
-
assert_raises(NoMethodError, "should not have found the attribute: #{new_attr_name} as a method") do
|
338
|
-
Person.new.send(new_attr_name)
|
339
|
-
end
|
340
|
-
assert_raises(NoMethodError, "should not have found the attribute: #{new_attr_name_two} as a method") do
|
341
|
-
Person.new.send(new_attr_name_two)
|
342
|
-
end
|
343
|
-
|
344
|
-
Person.schema = { new_attr_name.to_s => :float }
|
345
|
-
Person.schema { string new_attr_name_two }
|
346
|
-
|
347
|
-
assert_nothing_raised do
|
348
|
-
Person.new.send(new_attr_name)
|
349
|
-
Person.new.send(new_attr_name_two)
|
350
|
-
end
|
351
|
-
end
|
352
|
-
|
353
|
-
|
354
|
-
########
|
355
|
-
# Known attributes
|
356
|
-
#
|
357
|
-
# Attributes can be known to be attributes even if they aren't actually
|
358
|
-
# 'set' on a particular instance.
|
359
|
-
# This will only differ from 'attributes' if a schema has been set.
|
360
|
-
|
361
|
-
test "new model should have no known attributes" do
|
362
|
-
assert Person.known_attributes.blank?, "should have no known attributes"
|
363
|
-
assert Person.new.known_attributes.blank?, "should have no known attributes on a new instance"
|
364
|
-
end
|
365
|
-
|
366
|
-
test "setting schema should set known attributes on class and instance" do
|
367
|
-
new_schema = { "age" => "integer", "name" => "string",
|
368
|
-
"height" => "float", "bio" => "text",
|
369
|
-
"weight" => "decimal", "photo" => "binary",
|
370
|
-
"alive" => "boolean", "created_at" => "timestamp",
|
371
|
-
"thetime" => "time", "thedate" => "date", "mydatetime" => "datetime" }
|
372
|
-
|
373
|
-
assert_nothing_raised { Person.schema = new_schema }
|
374
|
-
|
375
|
-
assert_equal new_schema.keys.sort, Person.known_attributes.sort
|
376
|
-
assert_equal new_schema.keys.sort, Person.new.known_attributes.sort
|
377
|
-
end
|
378
|
-
|
379
|
-
test "known attributes on a fetched resource should return all the attributes of the instance" do
|
380
|
-
p = Person.find(1)
|
381
|
-
attrs = p.known_attributes
|
382
|
-
|
383
|
-
assert attrs.present?, "should have found some attributes!"
|
384
|
-
|
385
|
-
p.attributes.each do |the_attr, val|
|
386
|
-
assert attrs.include?(the_attr), "should have found attr: #{the_attr} in known attributes, but only had: #{attrs.inspect}"
|
387
|
-
end
|
388
|
-
end
|
389
|
-
|
390
|
-
test "with two instances, known attributes should match the attributes of the individual instances - even if they differ" do
|
391
|
-
matz = Person.find(1)
|
392
|
-
rick = Person.find(6)
|
393
|
-
|
394
|
-
m_attrs = matz.attributes.keys.sort
|
395
|
-
r_attrs = rick.attributes.keys.sort
|
396
|
-
|
397
|
-
assert_not_equal m_attrs, r_attrs, "should have different attributes on each model"
|
398
|
-
|
399
|
-
assert_not_equal matz.known_attributes, rick.known_attributes, "should have had different known attributes too"
|
400
|
-
end
|
401
|
-
|
402
|
-
test "setting schema then fetching should add schema attributes to the instance attributes" do
|
403
|
-
# an attribute in common with fetched instance and one that isn't
|
404
|
-
new_schema = { "age" => "integer", "name" => "string",
|
405
|
-
"height" => "float", "bio" => "text",
|
406
|
-
"weight" => "decimal", "photo" => "binary",
|
407
|
-
"alive" => "boolean", "created_at" => "timestamp",
|
408
|
-
"thetime" => "time", "thedate" => "date", "mydatetime" => "datetime" }
|
409
|
-
|
410
|
-
assert_nothing_raised { Person.schema = new_schema }
|
411
|
-
|
412
|
-
matz = Person.find(1)
|
413
|
-
known_attrs = matz.known_attributes
|
414
|
-
|
415
|
-
matz.attributes.keys.each do |the_attr|
|
416
|
-
assert known_attrs.include?(the_attr), "should have found instance attr: #{the_attr} in known attributes, but only had: #{known_attrs.inspect}"
|
417
|
-
end
|
418
|
-
new_schema.keys.each do |the_attr|
|
419
|
-
assert known_attrs.include?(the_attr), "should have found schema attr: #{the_attr} in known attributes, but only had: #{known_attrs.inspect}"
|
420
|
-
end
|
421
|
-
end
|
422
|
-
|
423
|
-
test "known attributes should be unique" do
|
424
|
-
new_schema = { "age" => "integer", "name" => "string" }
|
425
|
-
Person.schema = new_schema
|
426
|
-
assert_equal Person.new(age: 20, name: "Matz").known_attributes, ["age", "name"]
|
427
|
-
end
|
428
|
-
end
|
@@ -1,129 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "abstract_unit"
|
4
|
-
require "fixtures/person"
|
5
|
-
|
6
|
-
class BaseErrorsTest < ActiveSupport::TestCase
|
7
|
-
def setup
|
8
|
-
ActiveResource::HttpMock.respond_to do |mock|
|
9
|
-
mock.post "/people.xml", {}, %q(<?xml version="1.0" encoding="UTF-8"?><errors><error>Age can't be blank</error><error>Known attribute can't be blank</error><error>Name can't be blank</error><error>Name must start with a letter</error><error>Person quota full for today.</error><error>Phone work can't be blank</error><error>Phone is not valid</error></errors>), 422, "Content-Type" => "application/xml; charset=utf-8"
|
10
|
-
mock.post "/people.json", {}, %q({"errors":{"age":["can't be blank"],"known_attribute":["can't be blank"],"name":["can't be blank", "must start with a letter"],"person":["quota full for today."],"phone_work":["can't be blank"],"phone":["is not valid"]}}), 422, "Content-Type" => "application/json; charset=utf-8"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_should_mark_as_invalid
|
15
|
-
[ :json, :xml ].each do |format|
|
16
|
-
invalid_user_using_format(format) do
|
17
|
-
assert_not @person.valid?
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_should_parse_json_and_xml_errors
|
23
|
-
[ :json, :xml ].each do |format|
|
24
|
-
invalid_user_using_format(format) do
|
25
|
-
assert_kind_of ActiveResource::Errors, @person.errors
|
26
|
-
assert_equal 7, @person.errors.size
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_should_parse_json_errors_when_no_errors_key
|
32
|
-
ActiveResource::HttpMock.respond_to do |mock|
|
33
|
-
mock.post "/people.json", {}, "{}", 422, "Content-Type" => "application/json; charset=utf-8"
|
34
|
-
end
|
35
|
-
|
36
|
-
invalid_user_using_format(:json) do
|
37
|
-
assert_kind_of ActiveResource::Errors, @person.errors
|
38
|
-
assert_equal 0, @person.errors.size
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_should_parse_errors_to_individual_attributes
|
43
|
-
[ :json, :xml ].each do |format|
|
44
|
-
invalid_user_using_format(format) do
|
45
|
-
assert @person.errors[:name].any?
|
46
|
-
assert_equal ["can't be blank"], @person.errors[:age]
|
47
|
-
assert_equal ["can't be blank", "must start with a letter"], @person.errors[:name]
|
48
|
-
assert_equal ["can't be blank"], @person.errors[:phone_work]
|
49
|
-
assert_equal ["is not valid"], @person.errors[:phone]
|
50
|
-
assert_equal ["Person quota full for today."], @person.errors[:base]
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_should_parse_errors_to_known_attributes
|
56
|
-
[ :json, :xml ].each do |format|
|
57
|
-
invalid_user_using_format(format) do
|
58
|
-
assert_equal ["can't be blank"], @person.errors[:known_attribute]
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_should_iterate_over_errors
|
64
|
-
[ :json, :xml ].each do |format|
|
65
|
-
invalid_user_using_format(format) do
|
66
|
-
errors = []
|
67
|
-
if ActiveSupport.gem_version >= Gem::Version.new("6.1.x")
|
68
|
-
@person.errors.each { |error| errors << [error.attribute, error.message] }
|
69
|
-
else
|
70
|
-
@person.errors.each { |attribute, message| errors << [attribute, message] }
|
71
|
-
end
|
72
|
-
assert errors.include?([:name, "can't be blank"])
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_should_iterate_over_full_errors
|
78
|
-
[ :json, :xml ].each do |format|
|
79
|
-
invalid_user_using_format(format) do
|
80
|
-
errors = []
|
81
|
-
@person.errors.to_a.each { |message| errors << message }
|
82
|
-
assert errors.include?("Name can't be blank")
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_should_format_full_errors
|
88
|
-
[ :json, :xml ].each do |format|
|
89
|
-
invalid_user_using_format(format) do
|
90
|
-
full = @person.errors.full_messages
|
91
|
-
assert full.include?("Age can't be blank")
|
92
|
-
assert full.include?("Name can't be blank")
|
93
|
-
assert full.include?("Name must start with a letter")
|
94
|
-
assert full.include?("Person quota full for today.")
|
95
|
-
assert full.include?("Phone is not valid")
|
96
|
-
assert full.include?("Phone work can't be blank")
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_should_mark_as_invalid_when_content_type_is_unavailable_in_response_header
|
102
|
-
ActiveResource::HttpMock.respond_to do |mock|
|
103
|
-
mock.post "/people.xml", {}, %q(<?xml version="1.0" encoding="UTF-8"?><errors><error>Age can't be blank</error><error>Name can't be blank</error><error>Name must start with a letter</error><error>Person quota full for today.</error><error>Phone work can't be blank</error><error>Phone is not valid</error></errors>), 422, {}
|
104
|
-
mock.post "/people.json", {}, %q({"errors":{"age":["can't be blank"],"name":["can't be blank", "must start with a letter"],"person":["quota full for today."],"phone_work":["can't be blank"],"phone":["is not valid"]}}), 422, {}
|
105
|
-
end
|
106
|
-
|
107
|
-
[ :json, :xml ].each do |format|
|
108
|
-
invalid_user_using_format(format) do
|
109
|
-
assert_not @person.valid?
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
private
|
115
|
-
def invalid_user_using_format(mime_type_reference)
|
116
|
-
previous_format = Person.format
|
117
|
-
previous_schema = Person.schema
|
118
|
-
|
119
|
-
Person.format = mime_type_reference
|
120
|
-
Person.schema = { "known_attribute" => "string" }
|
121
|
-
@person = Person.new(name: "", age: "", phone: "", phone_work: "")
|
122
|
-
assert_equal false, @person.save
|
123
|
-
|
124
|
-
yield
|
125
|
-
ensure
|
126
|
-
Person.format = previous_format
|
127
|
-
Person.schema = previous_schema
|
128
|
-
end
|
129
|
-
end
|