word-count-validator 0.2.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,23 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ Gemfile.lock
23
+ .rbenv-version
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -0,0 +1,10 @@
1
+ ---
2
+ language: ruby
3
+ rvm:
4
+ - 1.8.7
5
+ - 1.9.2
6
+ - 1.9.3
7
+ - ree
8
+ notifications:
9
+ email:
10
+ - sutto@sutto.net
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in word-count-validator.gemspec
4
+ gemspec
data/Rakefile CHANGED
@@ -1,51 +1 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "word-count-validator"
8
- gem.summary = %Q{Makes validating word counts in active_model easy}
9
- gem.description = %Q{Provides validates_word_count which lets users validate a string has a minimum / maximum number of words.}
10
- gem.email = "sutto@sutto.net"
11
- gem.homepage = "http://github.com/Sutto/word-count-validator"
12
- gem.authors = ["Darcy Laycock", "Eric Anderson"]
13
- end
14
- Jeweler::GemcutterTasks.new
15
- rescue LoadError
16
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
17
- end
18
-
19
- require 'rake/testtask'
20
- Rake::TestTask.new(:test) do |test|
21
- test.libs << 'lib' << 'test'
22
- test.pattern = 'test/**/test_*.rb'
23
- test.verbose = true
24
- end
25
-
26
- begin
27
- require 'rcov/rcovtask'
28
- Rcov::RcovTask.new do |test|
29
- test.libs << 'test'
30
- test.pattern = 'test/**/test_*.rb'
31
- test.verbose = true
32
- end
33
- rescue LoadError
34
- task :rcov do
35
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
- end
37
- end
38
-
39
- task :test => :check_dependencies
40
-
41
- task :default => :test
42
-
43
- require 'rake/rdoctask'
44
- Rake::RDocTask.new do |rdoc|
45
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
-
47
- rdoc.rdoc_dir = 'rdoc'
48
- rdoc.title = "word-count-validator #{version}"
49
- rdoc.rdoc_files.include('README*')
50
- rdoc.rdoc_files.include('lib/**/*.rb')
51
- end
1
+ require "bundler/gem_tasks"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 1.0.0
@@ -1,4 +1,6 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  require 'active_model'
3
+ require 'action_controller'
2
4
  require 'active_support/i18n'
3
5
  I18n.load_path << File.expand_path(File.dirname(__FILE__) + "/../locale/en.yml")
4
6
 
@@ -48,7 +50,12 @@ module ActiveModel
48
50
  end
49
51
 
50
52
  def word_count_for(value)
51
- value.to_s.scan(/\w+/).size
53
+ if RUBY_VERSION =~ /1\.[0-8]\.*/
54
+ regexp = /\w+/u
55
+ else
56
+ regexp = /\p{Word}+/
57
+ end
58
+ value.to_s.scan(regexp).size
52
59
  end
53
60
 
54
61
  def base_options
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'shoulda'
5
+ require 'word-count-validator'
6
+ require 'rspec'
7
+
8
+ RSpec.configure do |config|
9
+
10
+ end
@@ -0,0 +1,34 @@
1
+ #encoding: utf-8
2
+
3
+ # -*- encoding : utf-8 -*-
4
+ require 'spec_helper'
5
+ require 'active_model'
6
+
7
+ class Validatable
8
+ include ActiveModel::Validations
9
+ validates_word_count :text, {:min => 5, :max => 7}
10
+ end
11
+
12
+ describe ActiveModel::Validations::WordCountValidator do
13
+ subject { Validatable.new }
14
+
15
+ context 'with a text of correct length' do
16
+ before { subject.stub(:text).and_return 'word '*5 }
17
+ it { should be_valid }
18
+ end
19
+
20
+ context 'with a text of incorrect length' do
21
+ before { subject.stub(:text).and_return 'word'*8 }
22
+ it { should_not be_valid }
23
+ end
24
+
25
+ context 'with a unicode text of correct length' do
26
+ before { subject.stub(:text).and_return 'Шла Саша по шосса и сосала сушку' }
27
+ it { should be_valid }
28
+ end
29
+
30
+ context 'with a unicode text of incorrect length' do
31
+ before { subject.stub(:text).and_return 'Шла Саша на хуй' }
32
+ it { should_not be_valid }
33
+ end
34
+ end
@@ -1,11 +1,10 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
5
2
 
3
+ $:.push File.expand_path("../lib", __FILE__)
4
+
6
5
  Gem::Specification.new do |s|
7
6
  s.name = %q{word-count-validator}
8
- s.version = "0.2.2"
7
+ s.version = "1.0.0"
9
8
 
10
9
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
10
  s.authors = ["Darcy Laycock", "Eric Anderson"]
@@ -16,27 +15,12 @@ Gem::Specification.new do |s|
16
15
  "LICENSE",
17
16
  "README.rdoc"
18
17
  ]
19
- s.files = [
20
- ".document",
21
- "LICENSE",
22
- "README.rdoc",
23
- "Rakefile",
24
- "VERSION",
25
- "lib/active_model/locale/en.yml",
26
- "lib/active_model/validations/word_count.rb",
27
- "lib/word-count-validator.rb",
28
- "test/helper.rb",
29
- "test/test_word-count-validator.rb",
30
- "word-count-validator.gemspec"
31
- ]
18
+ s.files = `git ls-files`.split("\n") + %w(LICENSE README.rdoc)
32
19
  s.homepage = %q{http://github.com/Sutto/word-count-validator}
33
20
  s.require_paths = ["lib"]
34
21
  s.rubygems_version = %q{1.3.7}
35
22
  s.summary = %q{Makes validating word counts in active_model easy}
36
- s.test_files = [
37
- "test/helper.rb",
38
- "test/test_word-count-validator.rb"
39
- ]
23
+ s.test_files = Dir.glob('spec/**/*')
40
24
 
41
25
  if s.respond_to? :specification_version then
42
26
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -47,5 +31,11 @@ Gem::Specification.new do |s|
47
31
  end
48
32
  else
49
33
  end
34
+
35
+ s.add_development_dependency "rspec", ">=2"
36
+ s.add_development_dependency "bundler"
37
+ s.add_development_dependency "shoulda"
38
+ s.add_development_dependency "rails"
39
+ s.add_development_dependency "jeweler"
50
40
  end
51
41
 
metadata CHANGED
@@ -1,36 +1,111 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: word-count-validator
3
- version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 2
9
- - 2
10
- version: 0.2.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Darcy Laycock
14
9
  - Eric Anderson
15
10
  autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
-
19
- date: 2010-12-11 00:00:00 +08:00
20
- default_executable:
21
- dependencies: []
22
-
23
- description: Provides validates_word_count which lets users validate a string has a minimum / maximum number of words.
13
+ date: 2010-12-11 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '2'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '2'
31
+ - !ruby/object:Gem::Dependency
32
+ name: bundler
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: shoulda
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: rails
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: jeweler
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ description: Provides validates_word_count which lets users validate a string has
96
+ a minimum / maximum number of words.
24
97
  email: sutto@sutto.net
25
98
  executables: []
26
-
27
99
  extensions: []
28
-
29
- extra_rdoc_files:
100
+ extra_rdoc_files:
30
101
  - LICENSE
31
102
  - README.rdoc
32
- files:
103
+ files:
33
104
  - .document
105
+ - .gitignore
106
+ - .rspec
107
+ - .travis.yml
108
+ - Gemfile
34
109
  - LICENSE
35
110
  - README.rdoc
36
111
  - Rakefile
@@ -38,43 +113,36 @@ files:
38
113
  - lib/active_model/locale/en.yml
39
114
  - lib/active_model/validations/word_count.rb
40
115
  - lib/word-count-validator.rb
41
- - test/helper.rb
42
- - test/test_word-count-validator.rb
116
+ - spec/spec_helper.rb
117
+ - spec/word_count_validator_spec.rb
43
118
  - word-count-validator.gemspec
44
- has_rdoc: true
45
119
  homepage: http://github.com/Sutto/word-count-validator
46
120
  licenses: []
47
-
48
121
  post_install_message:
49
122
  rdoc_options: []
50
-
51
- require_paths:
123
+ require_paths:
52
124
  - lib
53
- required_ruby_version: !ruby/object:Gem::Requirement
125
+ required_ruby_version: !ruby/object:Gem::Requirement
54
126
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ segments:
60
132
  - 0
61
- version: "0"
62
- required_rubygems_version: !ruby/object:Gem::Requirement
133
+ hash: 3303226964384764395
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
135
  none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- hash: 3
68
- segments:
69
- - 0
70
- version: "0"
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
71
140
  requirements: []
72
-
73
141
  rubyforge_project:
74
- rubygems_version: 1.3.7
142
+ rubygems_version: 1.8.24
75
143
  signing_key:
76
144
  specification_version: 3
77
145
  summary: Makes validating word counts in active_model easy
78
- test_files:
79
- - test/helper.rb
80
- - test/test_word-count-validator.rb
146
+ test_files:
147
+ - spec/spec_helper.rb
148
+ - spec/word_count_validator_spec.rb
@@ -1,10 +0,0 @@
1
- require 'rubygems'
2
- require 'test/unit'
3
- require 'shoulda'
4
-
5
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
- $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require 'word-count-validator'
8
-
9
- class Test::Unit::TestCase
10
- end
@@ -1,7 +0,0 @@
1
- require 'helper'
2
-
3
- class TestWordCountValidator < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
6
- end
7
- end