crazy_validators 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ gem 'activesupport'
5
5
 
6
6
  group :development, :test do
7
7
  gem "shoulda", ">= 0"
8
- gem "bundler", "~> 1.1.0"
8
+ gem "bundler", "~> 1.2.0"
9
9
  gem "jeweler", "~> 1.8.0"
10
10
  gem 'simplecov', :require => false
11
11
  gem 'to_slug'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "crazy_validators"
8
- s.version = "0.2.1"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Cyril Picard"]
12
- s.date = "2012-05-28"
12
+ s.date = "2012-10-15"
13
13
  s.description = " CrazyValidators enables easy validation of attributs of an ActiveModel class, such as alphanumericality, presence in a Blacklist. "
14
14
  s.email = "Cyril@picard.ch"
15
15
  s.extra_rdoc_files = [
@@ -36,10 +36,13 @@ Gem::Specification.new do |s|
36
36
  "lib/crazy_validators/word_count_validator.rb",
37
37
  "locales/en.yml",
38
38
  "locales/fr.yml",
39
+ "test/fixtures/alpha_num_model.rb",
39
40
  "test/fixtures/boolean_model.rb",
40
41
  "test/fixtures/simple_model.rb",
41
- "test/fixtures/string_model.rb",
42
+ "test/fixtures/slug_model.rb",
43
+ "test/fixtures/word_count_model.rb",
42
44
  "test/helper.rb",
45
+ "test/test_alpha_numericality.rb",
43
46
  "test/test_boolean_validator.rb",
44
47
  "test/test_crazy_validators.rb",
45
48
  "test/test_slug_validator.rb",
@@ -48,7 +51,7 @@ Gem::Specification.new do |s|
48
51
  s.homepage = "http://github.com/cyrilpic/crazy_validators"
49
52
  s.licenses = ["MIT"]
50
53
  s.require_paths = ["lib"]
51
- s.rubygems_version = "1.8.19"
54
+ s.rubygems_version = "1.8.24"
52
55
  s.summary = "Adds some validation methods for ActiveModel models"
53
56
 
54
57
  if s.respond_to? :specification_version then
@@ -58,7 +61,7 @@ Gem::Specification.new do |s|
58
61
  s.add_runtime_dependency(%q<activemodel>, [">= 0"])
59
62
  s.add_runtime_dependency(%q<activesupport>, [">= 0"])
60
63
  s.add_development_dependency(%q<shoulda>, [">= 0"])
61
- s.add_development_dependency(%q<bundler>, ["~> 1.1.0"])
64
+ s.add_development_dependency(%q<bundler>, ["~> 1.2.0"])
62
65
  s.add_development_dependency(%q<jeweler>, ["~> 1.8.0"])
63
66
  s.add_development_dependency(%q<simplecov>, [">= 0"])
64
67
  s.add_development_dependency(%q<to_slug>, [">= 0"])
@@ -67,7 +70,7 @@ Gem::Specification.new do |s|
67
70
  s.add_dependency(%q<activemodel>, [">= 0"])
68
71
  s.add_dependency(%q<activesupport>, [">= 0"])
69
72
  s.add_dependency(%q<shoulda>, [">= 0"])
70
- s.add_dependency(%q<bundler>, ["~> 1.1.0"])
73
+ s.add_dependency(%q<bundler>, ["~> 1.2.0"])
71
74
  s.add_dependency(%q<jeweler>, ["~> 1.8.0"])
72
75
  s.add_dependency(%q<simplecov>, [">= 0"])
73
76
  s.add_dependency(%q<to_slug>, [">= 0"])
@@ -77,7 +80,7 @@ Gem::Specification.new do |s|
77
80
  s.add_dependency(%q<activemodel>, [">= 0"])
78
81
  s.add_dependency(%q<activesupport>, [">= 0"])
79
82
  s.add_dependency(%q<shoulda>, [">= 0"])
80
- s.add_dependency(%q<bundler>, ["~> 1.1.0"])
83
+ s.add_dependency(%q<bundler>, ["~> 1.2.0"])
81
84
  s.add_dependency(%q<jeweler>, ["~> 1.8.0"])
82
85
  s.add_dependency(%q<simplecov>, [">= 0"])
83
86
  s.add_dependency(%q<to_slug>, [">= 0"])
@@ -3,7 +3,7 @@ require 'oembed'
3
3
  module CrazyValidators
4
4
  class OEmbedUrlValidator < ActiveModel::EachValidator
5
5
 
6
- RESERVED_OPTIONS = [:type, :success]
6
+ RESERVED_OPTIONS = [:type, :success, :maxwidth, :maxheight]
7
7
  AUTHORIZED_TYPES = ['video', 'link', 'photo', 'rich']
8
8
 
9
9
  def initialize(options)
@@ -15,10 +15,13 @@ module CrazyValidators
15
15
  type = [options[:type]].flatten.map(&:to_s).keep_if do |e|
16
16
  AUTHORIZED_TYPES.include? e
17
17
  end
18
+ oembed_options = options.extract!(:maxwidth, :maxheight).keep_if do |k,v|
19
+ v.is_a? Fixnum
20
+ end
18
21
  if record.send(attribute.to_s + "_changed?")
19
22
  OEmbed::Providers.register_all
20
23
  begin
21
- res = OEmbed::Providers.get(value)
24
+ res = OEmbed::Providers.get(value, oembed_options)
22
25
  if type.any? { |t| res.send(t+'?') }
23
26
  unless options[:success].nil?
24
27
  if options[:success].is_a? Proc
@@ -0,0 +1,5 @@
1
+ require 'fixtures/simple_model'
2
+ class AlphaNumModel < SimpleModel
3
+ attributes :attri
4
+ validates :attri, alpha_numericality: true
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'fixtures/simple_model'
2
+ class SlugModel < SimpleModel
3
+ attributes :slug
4
+ validates :slug, slug: true
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'fixtures/simple_model'
2
+ class WordCountModel < SimpleModel
3
+ attributes :minmax
4
+ validates :minmax, word_count: { maximum: 10, minimum: 5 }
5
+ attributes :exact
6
+ validates :exact, word_count: { is: 5 }
7
+ end
@@ -0,0 +1,18 @@
1
+ require 'helper'
2
+ require 'fixtures/alpha_num_model'
3
+
4
+ class TestAlphaNumericalityValidator < Test::Unit::TestCase
5
+ include ActiveModel::Lint::Tests
6
+ def setup
7
+ @model = AlphaNumModel.new
8
+ end
9
+
10
+ should "only validate alpha numerical values" do
11
+ model.attri = "Hello world"
12
+ assert !model.valid?, model.errors[:attri].first
13
+ model.attri = "hello"
14
+ assert model.valid?
15
+ model.attri = "hello45"
16
+ assert model.valid?
17
+ end
18
+ end
@@ -1,16 +1,15 @@
1
1
  require 'helper'
2
- require 'fixtures/string_model'
2
+ require 'fixtures/slug_model'
3
3
 
4
4
  class TestSlugValidator < Test::Unit::TestCase
5
5
  include ActiveModel::Lint::Tests
6
6
  def setup
7
- StringModel.validates :string, slug: true
8
- @model = StringModel.new
7
+ @model = SlugModel.new
9
8
  end
10
9
  should "only accept valid slug" do
11
- model.string = "This is @ regular sentance !"
10
+ model.slug = "This is @ regular sentance !"
12
11
  assert !model.valid?, "Provided a sentance instead of a slug"
13
- model.string = "This is @ regular sentance !".to_slug
12
+ model.slug = "This is @ regular sentance !".to_slug
14
13
  assert model.valid?
15
14
  end
16
15
  end
@@ -0,0 +1,39 @@
1
+ require 'helper'
2
+ require 'fixtures/word_count_model'
3
+
4
+ class TestWordCountValidator < Test::Unit::TestCase
5
+ include ActiveModel::Lint::Tests
6
+ def setup
7
+ @model = WordCountModel.new
8
+ end
9
+
10
+ should "only validate valid input between 5 and 10 words" do
11
+ text2 = "Hello World"
12
+ text4 = "Hello World from home."
13
+ text5 = "Hello World from my home."
14
+ text11 = "Hello World from my very sweet home in Switzerland, Geneva Lake."
15
+
16
+ model.minmax = text5
17
+ model.exact = text2
18
+ assert !model.valid?
19
+
20
+ model.exact = text11
21
+ assert !model.valid?
22
+
23
+ model.exact = text4
24
+ assert !model.valid?
25
+
26
+ model.exact = text5
27
+ assert model.valid?
28
+
29
+ model.minmax = text2
30
+ assert !model.valid?
31
+
32
+ model.minmax = text4
33
+ assert !model.valid?
34
+
35
+ model.minmax = text11
36
+ assert !model.valid?
37
+ end
38
+
39
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crazy_validators
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-28 00:00:00.000000000 Z
12
+ date: 2012-10-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -66,7 +66,7 @@ dependencies:
66
66
  requirements:
67
67
  - - ~>
68
68
  - !ruby/object:Gem::Version
69
- version: 1.1.0
69
+ version: 1.2.0
70
70
  type: :development
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -74,7 +74,7 @@ dependencies:
74
74
  requirements:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: 1.1.0
77
+ version: 1.2.0
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: jeweler
80
80
  requirement: !ruby/object:Gem::Requirement
@@ -167,10 +167,13 @@ files:
167
167
  - lib/crazy_validators/word_count_validator.rb
168
168
  - locales/en.yml
169
169
  - locales/fr.yml
170
+ - test/fixtures/alpha_num_model.rb
170
171
  - test/fixtures/boolean_model.rb
171
172
  - test/fixtures/simple_model.rb
172
- - test/fixtures/string_model.rb
173
+ - test/fixtures/slug_model.rb
174
+ - test/fixtures/word_count_model.rb
173
175
  - test/helper.rb
176
+ - test/test_alpha_numericality.rb
174
177
  - test/test_boolean_validator.rb
175
178
  - test/test_crazy_validators.rb
176
179
  - test/test_slug_validator.rb
@@ -190,7 +193,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
190
193
  version: '0'
191
194
  segments:
192
195
  - 0
193
- hash: 2631497578937373577
196
+ hash: 1647732643492294825
194
197
  required_rubygems_version: !ruby/object:Gem::Requirement
195
198
  none: false
196
199
  requirements:
@@ -199,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
202
  version: '0'
200
203
  requirements: []
201
204
  rubyforge_project:
202
- rubygems_version: 1.8.19
205
+ rubygems_version: 1.8.24
203
206
  signing_key:
204
207
  specification_version: 3
205
208
  summary: Adds some validation methods for ActiveModel models
@@ -1,4 +0,0 @@
1
- require 'fixtures/simple_model'
2
- class StringModel < SimpleModel
3
- attributes :string
4
- end