slim_validation 0.0.2 → 0.0.3

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: 688db431528d6795e1a0efb837cf04a7f84993f4
4
- data.tar.gz: 4eef5249a02405b8d099912eddb1dcb0075741d6
3
+ metadata.gz: eb337db1e25a1983778c7d611c726f78ee2e3452
4
+ data.tar.gz: 1d6ca65d94e1f77f5877bbe346dbb03691f867f2
5
5
  SHA512:
6
- metadata.gz: b352e7c36192e7685d6a0fc4b32bead5c63b96996e4254ab7816e57ee40838d41c002229cc8dac770c225426c1d6d0109a26250277d8f90d233b0c7e742f80da
7
- data.tar.gz: 1ae6817df54e8102766a5268ffd00848c3a3d484c2b12812a550e689d0c52c82f2a8c9beafa5b036e1e31883a66d7e3d32d8e573c15e5a9c941987c777430bff
6
+ metadata.gz: fada04684b322af96d1aa64e00adce11a4ad54d746e6b8746e948a58c689daa4c2d6f64cf3e0a04b3b71fc6ef808dc0e9b8382c237b734567107f805533e5a44
7
+ data.tar.gz: a24705ae343091d344a585889418e31861549019108daf93c28e5ac74ec206192516ad83a42fa22adaca2e74bbea062071e1b4e30b1cdc7e9414190644e4f827
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- slim_validation (0.0.1)
4
+ slim_validation (0.0.2)
5
5
  rails (~> 4.0)
6
6
  slim
7
7
 
@@ -6,11 +6,14 @@ require 'slim'
6
6
  class SlimValidator < ActiveModel::EachValidator
7
7
  def validate_each(record, attr_name, value)
8
8
  result = Slim::Template.new(options[:options]) { value }.render(options[:scope] == :record ? record : options[:scope])
9
- rescue
9
+ rescue => e
10
+ if (error_storer = options[:error]).present?
11
+ record.send("#{error_storer}=", e)
12
+ end
10
13
  record.errors.add(attr_name, :invalid_slim, options)
11
14
  ensure
12
15
  if (to = options[:to]).present?
13
- to.is_a?(Proc) ? to.(record, result) : record[to] = result
16
+ to.is_a?(Proc) ? to.(record, result) : record.send("#{to}=", result)
14
17
  end
15
18
  end
16
19
  end
@@ -1,3 +1,3 @@
1
1
  module SlimValidation
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,4 +1,6 @@
1
1
  class Entry < ActiveRecord::Base
2
+ attr_accessor :slim_error
3
+
2
4
  validates :slim,
3
5
  slim: {
4
6
  allow_blank: true
@@ -31,6 +33,7 @@ class Entry < ActiveRecord::Base
31
33
  options: {pretty: false},
32
34
  to: :html,
33
35
  scope: :record,
36
+ error: :slim_error,
34
37
  allow_blank: true
35
38
  }
36
39
 
@@ -7,6 +7,16 @@ RSpec.describe Entry, type: :model do
7
7
  it { expect { create(:entry, slim_proc: invalid_slim) }.to raise_exception(ActiveRecord::RecordInvalid) }
8
8
  it { expect { create(:entry, slim_attribute: invalid_slim) }.to raise_exception(ActiveRecord::RecordInvalid) }
9
9
  it { expect { create(:entry, slim_scope: invalid_slim) }.to raise_exception(ActiveRecord::RecordInvalid) }
10
+
11
+ context 'with error storer' do
12
+ let(:entry) do
13
+ entry = build(:entry, slim_scope: invalid_slim)
14
+ entry.valid?
15
+ entry
16
+ end
17
+ it { expect(entry.slim_error).to be_truthy }
18
+ end
19
+
10
20
  end
11
21
 
12
22
  context 'when added valid slim' do
@@ -39,6 +49,11 @@ RSpec.describe Entry, type: :model do
39
49
  it { expect(entry).to be_a(Entry) }
40
50
  it { expect(entry.html).to eq('<header><h1>local value</h1></header><section><p>content</p></section><footer><p>2010/05/09</p></footer>') }
41
51
  end
52
+
53
+ context 'with error storer' do
54
+ let(:entry) { create(:entry, slim_scope: valid_slim) }
55
+ it { expect(entry.slim_error).to be_nil }
56
+ end
42
57
  end
43
58
  end
44
59
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slim_validation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - mmmpa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-11 00:00:00.000000000 Z
11
+ date: 2015-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails