eots 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7333f8e012a365f06d6873c7e74d3c64921a4187
4
- data.tar.gz: 74235b892a45452e64849da2dccb65a8463204c6
3
+ metadata.gz: 7c34e8989da8f7298f12e708af62be46a4392a2c
4
+ data.tar.gz: bbc994de39a28e60338a1075fcd64211add19425
5
5
  SHA512:
6
- metadata.gz: 8663169bd4e64e78d1847d737d7880dda33b2444a20ef54e3cdef7d96e763e0a931590dc6290f64113b95a045efef8c8951f4e86416194b6c808832c86fa06a9
7
- data.tar.gz: 3b7e7270746ee1ae2a435ddff965b7cfb910321b679f1282c866f5f81bb461b6e5927082ae09e74a954458ce1687f561286ed78bcee4d2731f20c69356aae1ce
6
+ metadata.gz: ec89ba3845b92a1ac9876cb34d8d61bdab8d567f029a4fba6f284c74b60c8c8fb51f7cccb00af46587e122c44048702285715efe6124bb7beee853153c142e30
7
+ data.tar.gz: ce6ec1ca9a3ebf3d941e7498259ee37fc5d0779a5d51f11c59fc86839464907d25080cf433f3ddd7e3de00b457d100dfabd936e064bae6e255c20d45ddc587b3
@@ -1,4 +1,4 @@
1
- Copyright 2016 Dave Aronson
1
+ Copyright 2016-2017 Dave Aronson
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -1,6 +1,7 @@
1
1
  class EOTS::Email # an instance, as opposed to the whole kind
2
2
 
3
3
  MissingRequiredFieldsError = Class.new(RuntimeError)
4
+ MismatchedFieldError = Class.new(RuntimeError)
4
5
 
5
6
  attr_reader :kind, :values
6
7
 
@@ -25,6 +26,7 @@ class EOTS::Email # an instance, as opposed to the whole kind
25
26
  %w(action controller authenticity_token commit kind utf8).each { |k| values.delete k }
26
27
  check_value_names(values, kind) if values.any?
27
28
  check_required_fields(values, kind)
29
+ check_required_matches(values, kind)
28
30
  self.new(kind, values)
29
31
  end
30
32
 
@@ -46,9 +48,7 @@ class EOTS::Email # an instance, as opposed to the whole kind
46
48
 
47
49
  def self.check_required_fields(values, kind)
48
50
  required = kind.form_fields.values.flatten.select { |f| f.required? }.map(&:name)
49
- puts "required: #{ required.map { |n| "#{n} (#{n.class.name})" }.join(", ") }"
50
51
  given = values.keys
51
- puts "given: #{ given.map { |n| "#{n} (#{n.class.name})" }.join(", ") }"
52
52
  missing = required - given
53
53
  if missing.any?
54
54
  raise(MissingRequiredFieldsError,
@@ -56,6 +56,17 @@ class EOTS::Email # an instance, as opposed to the whole kind
56
56
  end
57
57
  end
58
58
 
59
+ def self.check_required_matches(values, kind)
60
+ mismatches = kind.form_fields.values.flatten.select do |f|
61
+ (reqd = f.must_match) && values[f.name] != reqd
62
+ end
63
+ if mismatches.any?
64
+ list = mismatches.map { |f| "'#{f.name}'" }.join(", ")
65
+ raise(EOTS::Email::MismatchedFieldError,
66
+ "Incorrect answers on field(s) #{list}")
67
+ end
68
+ end
69
+
59
70
  def self.check_value_names(values, kind)
60
71
  field_names = kind.form_fields.values.flatten.map &:name
61
72
  errs = values.keys.reject { |key| field_names.include? key }
@@ -3,7 +3,7 @@ class EOTS::Field
3
3
  AlreadyDefinedError = Class.new(RuntimeError)
4
4
  InvalidSectionError = Class.new(RuntimeError)
5
5
 
6
- attr_reader :name, :label, :caption, :section, :html_options
6
+ attr_reader :name, :label, :caption, :section, :html_options, :must_match
7
7
 
8
8
  def initialize(name, label, options={})
9
9
  @name = name.to_s
@@ -11,6 +11,7 @@ class EOTS::Field
11
11
  opts = options.dup
12
12
  @caption = opts.delete(:caption)
13
13
  @section = opts.delete(:section) || :body
14
+ @must_match = opts.delete(:must_match)
14
15
  unless [:header, :body, :footer].include? @section
15
16
  raise(InvalidSectionError,
16
17
  "Invalid section '#{@section}' -- must be :header, :body, or :footer")
@@ -1,3 +1,3 @@
1
1
  module EOTS
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/dave/computer/opensource/eots
3
3
  specs:
4
- eots (0.0.2)
4
+ eots (0.0.4)
5
5
  rails
6
6
 
7
7
  GEM
@@ -126,4 +126,4 @@ DEPENDENCIES
126
126
  rspec-rails
127
127
 
128
128
  BUNDLED WITH
129
- 1.11.2
129
+ 1.13.7
@@ -695,3 +695,83 @@ Processing by EOTS::EOTSController#show as HTML
695
695
  Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.2ms)
696
696
  Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/show.html.erb within layouts/application (8.0ms)
697
697
  Completed 200 OK in 143ms (Views: 139.9ms)
698
+ Started GET "/contact_emails/inner_kind" for 127.0.0.1 at 2016-07-24 19:17:02 -0400
699
+ Processing by EOTS::EOTSController#show as HTML
700
+ Parameters: {"kind"=>"inner_kind"}
701
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.6ms)
702
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.2ms)
703
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.2ms)
704
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/show.html.erb within layouts/application (6.2ms)
705
+ Completed 200 OK in 145ms (Views: 141.4ms)
706
+ Started GET "/contact_emails/inner_kind" for 127.0.0.1 at 2016-07-24 19:21:06 -0400
707
+ Processing by EOTS::EOTSController#show as HTML
708
+ Parameters: {"kind"=>"inner_kind"}
709
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.5ms)
710
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.2ms)
711
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.2ms)
712
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/show.html.erb within layouts/application (5.6ms)
713
+ Completed 200 OK in 141ms (Views: 137.9ms)
714
+ Started GET "/contact_emails/inner_kind" for 127.0.0.1 at 2017-06-14 12:50:50 -0400
715
+ Processing by EOTS::EOTSController#show as HTML
716
+ Parameters: {"kind"=>"inner_kind"}
717
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.8ms)
718
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.2ms)
719
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.2ms)
720
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/show.html.erb within layouts/application (8.6ms)
721
+ Completed 200 OK in 171ms (Views: 166.7ms)
722
+ Started GET "/contact_emails/inner_kind" for 127.0.0.1 at 2017-06-14 13:01:58 -0400
723
+ Processing by EOTS::EOTSController#show as HTML
724
+ Parameters: {"kind"=>"inner_kind"}
725
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.6ms)
726
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.2ms)
727
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.2ms)
728
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/show.html.erb within layouts/application (6.8ms)
729
+ Completed 200 OK in 157ms (Views: 153.7ms)
730
+ Started GET "/contact_emails/inner_kind" for 127.0.0.1 at 2017-06-14 13:03:06 -0400
731
+ Processing by EOTS::EOTSController#show as HTML
732
+ Parameters: {"kind"=>"inner_kind"}
733
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.6ms)
734
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.2ms)
735
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.3ms)
736
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/show.html.erb within layouts/application (5.8ms)
737
+ Completed 200 OK in 148ms (Views: 145.0ms)
738
+ Started GET "/contact_emails/inner_kind" for 127.0.0.1 at 2017-06-14 13:03:52 -0400
739
+ Processing by EOTS::EOTSController#show as HTML
740
+ Parameters: {"kind"=>"inner_kind"}
741
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.7ms)
742
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.3ms)
743
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.3ms)
744
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/show.html.erb within layouts/application (8.5ms)
745
+ Completed 200 OK in 168ms (Views: 164.6ms)
746
+ Started GET "/contact_emails/inner_kind" for 127.0.0.1 at 2017-06-14 13:04:44 -0400
747
+ Processing by EOTS::EOTSController#show as HTML
748
+ Parameters: {"kind"=>"inner_kind"}
749
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.5ms)
750
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.2ms)
751
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.2ms)
752
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/show.html.erb within layouts/application (5.7ms)
753
+ Completed 200 OK in 151ms (Views: 147.7ms)
754
+ Started GET "/contact_emails/inner_kind" for 127.0.0.1 at 2017-06-14 13:04:52 -0400
755
+ Processing by EOTS::EOTSController#show as HTML
756
+ Parameters: {"kind"=>"inner_kind"}
757
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.5ms)
758
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.2ms)
759
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.2ms)
760
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/show.html.erb within layouts/application (5.6ms)
761
+ Completed 200 OK in 141ms (Views: 138.6ms)
762
+ Started GET "/contact_emails/inner_kind" for 127.0.0.1 at 2017-06-14 13:05:44 -0400
763
+ Processing by EOTS::EOTSController#show as HTML
764
+ Parameters: {"kind"=>"inner_kind"}
765
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.6ms)
766
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.2ms)
767
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.3ms)
768
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/show.html.erb within layouts/application (5.9ms)
769
+ Completed 200 OK in 153ms (Views: 149.3ms)
770
+ Started GET "/contact_emails/inner_kind" for 127.0.0.1 at 2017-06-14 13:06:12 -0400
771
+ Processing by EOTS::EOTSController#show as HTML
772
+ Parameters: {"kind"=>"inner_kind"}
773
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.6ms)
774
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.2ms)
775
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/_field.html.erb (0.2ms)
776
+ Rendered /Users/dave/computer/opensource/eots/app/views/eots/eots/show.html.erb within layouts/application (5.9ms)
777
+ Completed 200 OK in 143ms (Views: 140.0ms)
@@ -20,6 +20,10 @@ describe EOTS do
20
20
  required: true,
21
21
  section: :footer)
22
22
 
23
+ EOTS::field("captcha", "CAPTCHA",
24
+ must_match: "Captcha",
25
+ section: :footer)
26
+
23
27
  EOTS::email_kind("general") do
24
28
  EOTS::field("body", "What do you want to tell or ask us?",
25
29
  type: :textarea, rows: 5, columns: 60, maxlength: 1024,
@@ -87,12 +91,21 @@ describe EOTS do
87
91
  describe "#send_email" do
88
92
  describe "checks requiredness of fields" do
89
93
  it "barfs if any are missing" do
90
- params = HashWithIndifferentAccess.new({ kind: "general" })
94
+ params = HashWithIndifferentAccess.new({ kind: "general",
95
+ captcha: "Captcha" })
91
96
  expect { EOTS::Email.create_from_params(params) }.
92
97
  to raise_error(EOTS::Email::MissingRequiredFieldsError)
93
98
  end
94
- it "doesn't barfs if all are supplied" do
99
+ it "barfs if any mismatch a required specific answer" do
100
+ params = HashWithIndifferentAccess.new({ kind: "general",
101
+ captcha: "something else",
102
+ not_spambot: true })
103
+ expect { EOTS::Email.create_from_params(params) }.
104
+ to raise_error(EOTS::Email::MismatchedFieldError)
105
+ end
106
+ it "doesn't barfs if all are supplied and correct" do
95
107
  params = HashWithIndifferentAccess.new({ kind: "general",
108
+ captcha: "Captcha",
96
109
  not_spambot: true })
97
110
  expect { EOTS::Email.create_from_params(params) }.not_to raise_error
98
111
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eots
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Aronson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-24 00:00:00.000000000 Z
11
+ date: 2017-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -40,8 +40,7 @@ dependencies:
40
40
  version: '0'
41
41
  description: Gem to programmatically declare multiples kinds of email and automagically
42
42
  construct forms, including view, routes, controller, etc.
43
- email:
44
- - github.2.trex@codosaur.us
43
+ email:
45
44
  executables: []
46
45
  extensions: []
47
46
  extra_rdoc_files: []