strong_locals 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f44d25786974527d01bdad6d6d5c9c3019d2cf12
4
+ data.tar.gz: 3fee10655b0c30e4a0812fd0cc2740802e9e4248
5
+ SHA512:
6
+ metadata.gz: a9d1cafd6b14725d0c93163a7f684011efb049446a9d987c1f8532f8d217f0a7c23fa0a52bfec5a8393aeb991840749410d336c137bb76aba896b9f533f9825e
7
+ data.tar.gz: fd726dd52821d2f74e34bc6b723dffeb58823366b8a54692caa6cefc019fa26f24d3548ef482ed4f403e5bc4d3888524e275637e09a8019cdaa4680b36621257
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+ # coding: utf-8
3
+
4
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
5
+ RSpec.configure do |config|
6
+ config.expect_with :rspec do |expectations|
7
+ # This option will default to `true` in RSpec 4. It makes the `description`
8
+ # and `failure_message` of custom matchers include text for helper methods
9
+ # defined using `chain`, e.g.:
10
+ # be_bigger_than(2).and_smaller_than(4).description
11
+ # # => "be bigger than 2 and smaller than 4"
12
+ # ...rather than:
13
+ # # => "be bigger than 2"
14
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
15
+ end
16
+
17
+ config.mock_with :rspec do |mocks|
18
+ # Prevents you from mocking or stubbing a method that does not exist on
19
+ # a real object. This is generally recommended, and will default to
20
+ # `true` in RSpec 4.
21
+ mocks.verify_partial_doubles = true
22
+ end
23
+
24
+ # These two settings work together to allow you to limit a spec run
25
+ # to individual examples or groups you care about by tagging them with
26
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
27
+ # get run.
28
+ config.filter_run :focus
29
+ config.run_all_when_everything_filtered = true
30
+
31
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
32
+ # For more details, see:
33
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
34
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
35
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
36
+ config.disable_monkey_patching!
37
+
38
+ # This setting enables warnings. It's recommended, but in some cases may
39
+ # be too noisy due to issues in dependencies.
40
+ config.warnings = true
41
+
42
+ # Many RSpec users commonly either run the entire suite or an individual
43
+ # file, and it's useful to allow more verbose output when running an
44
+ # individual spec file.
45
+ if config.files_to_run.one?
46
+ # Use the documentation formatter for detailed output,
47
+ # unless a formatter has already been configured
48
+ # (e.g. via a command-line flag).
49
+ config.default_formatter = "doc"
50
+ end
51
+
52
+ # Print the 10 slowest examples and example groups at the
53
+ # end of the spec run, to help surface which specs are running
54
+ # particularly slow.
55
+ config.profile_examples = 10
56
+
57
+ # Run specs in random order to surface order dependencies. If you find an
58
+ # order dependency and want to debug it, you can fix the order by providing
59
+ # the seed, which is printed after each run.
60
+ # --seed 1234
61
+ config.order = :random
62
+
63
+ # Seed global randomization in this process using the `--seed` CLI option.
64
+ # Setting this allows you to use `--seed` to deterministically reproduce
65
+ # test failures related to randomization by passing the same `--seed` value
66
+ # as the one that triggered the failure.
67
+ Kernel.srand config.seed
68
+ end
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+ require 'strong_locals'
3
+
4
+ RSpec.describe StrongLocals::Locals do
5
+ it 'adds locals' do
6
+ locals = StrongLocals::Locals.add(:name).add(:age)
7
+ expect(locals.locals.keys).to eq([:name, :age])
8
+ end
9
+
10
+ it 'validates required' do
11
+ local_assigns = {name: 'Leigh'}
12
+ locals = StrongLocals::Locals.
13
+ add(:name, required: true).
14
+ add(:age, required: true)
15
+
16
+ expect(locals.validate(local_assigns)).to eq({
17
+ age: ["required", "not present"]
18
+ })
19
+ end
20
+
21
+ it 'validates presence' do
22
+ local_assigns = {name: nil, age: nil}
23
+ locals = StrongLocals::Locals.
24
+ add(:name, required: true).
25
+ add(:age, required: true, presence: false)
26
+
27
+ expect(locals.validate(local_assigns)).to eq({
28
+ name: ["not present"]
29
+ })
30
+ end
31
+
32
+ it 'validates collection' do
33
+ local_assigns = {names: [], ages: 10}
34
+ locals = StrongLocals::Locals.
35
+ add(:names, collection: true).
36
+ add(:ages, collection: true)
37
+
38
+ expect(locals.validate(local_assigns)).to eq({
39
+ ages: ["not collection"]
40
+ })
41
+ end
42
+
43
+ it 'validates model' do
44
+ module ActiveRecord
45
+ class Base
46
+ end
47
+ end
48
+
49
+ class Alpaca < ActiveRecord::Base
50
+ end
51
+
52
+ local_assigns = {alpaca: Alpaca.new, llama: 'Spitty'}
53
+ locals = StrongLocals::Locals.
54
+ add(:alpaca, model: true).
55
+ add(:llama, model: true)
56
+
57
+ expect(locals.validate(local_assigns)).to eq({
58
+ ages: ["not model"]
59
+ })
60
+ end
61
+
62
+ it 'validates numeric' do
63
+ local_assigns = {eyes: 2, age: 'Old'}
64
+ locals = StrongLocals::Locals.
65
+ add(:eyes, numeric: true).
66
+ add(:age, numeric: true)
67
+
68
+ expect(locals.validate(local_assigns)).to eq({
69
+ name: ["not numeric"]
70
+ })
71
+ end
72
+
73
+ it 'raises exception' do
74
+ local_assigns = {name: 'Leigh'}
75
+ locals = StrongLocals::Locals.
76
+ add(:name).
77
+ add(:age)
78
+
79
+ expect {
80
+ locals.validate!(local_assigns)
81
+ }.to raise_error(StrongLocals::LocalsException)
82
+ end
83
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: strong_locals
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Leigh Halliday
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ description: StrongLocals is a gem for verifying the local variables passed to partials.
28
+ email:
29
+ - leighhalliday@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - spec/spec_helper.rb
35
+ - spec/strong_locals/locals_spec.rb
36
+ homepage: https://github.com/leighhalliday/strong_locals
37
+ licenses:
38
+ - MIT
39
+ metadata: {}
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 2.6.10
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: StrongLocals is a gem for verifying the local variables passed to partials.
60
+ test_files:
61
+ - spec/spec_helper.rb
62
+ - spec/strong_locals/locals_spec.rb