quick_shoulda 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +0 -1
- data/.travis.yml +1 -0
- data/Rakefile +5 -1
- data/lib/quick_shoulda/helpers/string_helpers.rb +2 -1
- data/lib/quick_shoulda/path_resolver.rb +1 -1
- data/lib/quick_shoulda/version.rb +1 -1
- data/quick_shoulda.gemspec +1 -1
- data/spec/generator/association_spec.rb +5 -0
- data/spec/generator/validation_spec.rb +24 -53
- metadata +14 -8
data/.rspec
CHANGED
data/.travis.yml
CHANGED
data/Rakefile
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
require "quick_shoulda/version.rb"
|
3
|
+
require 'rspec/core/rake_task'
|
3
4
|
|
4
5
|
task :install_mah_gem do
|
5
6
|
exec %{
|
6
7
|
gem uninstall quick_shoulda;
|
7
8
|
gem build quick_shoulda.gemspec;
|
8
9
|
gem install quick_shoulda-#{QuickShoulda::VERSION}.gem; }
|
9
|
-
end
|
10
|
+
end
|
11
|
+
|
12
|
+
task :default => :spec
|
13
|
+
RSpec::Core::RakeTask.new
|
@@ -29,7 +29,7 @@ module QuickShoulda
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def is_a_constant?(path)
|
32
|
-
( path[0] =~ /[A-Z]/ || path[0] =~ /:/ ) && File.extname(path).empty? && !path.include?('/')
|
32
|
+
( path[0].chr =~ /[A-Z]/ || path[0].chr =~ /:/ ) && File.extname(path).empty? && !path.include?('/')
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
data/quick_shoulda.gemspec
CHANGED
@@ -23,6 +23,11 @@ describe 'QuickShoulda::Generator::Association' do
|
|
23
23
|
"it { should belong_to(:friendly_user).dependent(:destroy).class_name('User').order('users.email DESC').with_foreign_key('friendly_user_id') }"
|
24
24
|
end
|
25
25
|
|
26
|
+
before do
|
27
|
+
should_receive(:shoulda_assciation_option_methods_chain).with(options).
|
28
|
+
and_return(".dependent(:destroy).class_name('User').order('users.email DESC').with_foreign_key('friendly_user_id')")
|
29
|
+
end
|
30
|
+
|
26
31
|
it 'should return valid shoulda test case' do
|
27
32
|
send(:generate_for_association, association).should eq expected
|
28
33
|
end
|
@@ -4,54 +4,25 @@ describe 'QuickShoulda::Generator::Validation' do
|
|
4
4
|
include QuickShoulda::StringHelpers
|
5
5
|
include QuickShoulda::Generator::Validation
|
6
6
|
|
7
|
-
describe '#
|
8
|
-
let(:
|
9
|
-
|
10
|
-
let(:
|
11
|
-
let(:
|
12
|
-
|
13
|
-
let(:
|
14
|
-
|
15
|
-
let(:exclusion_options) { { in: ['a', 'b', 'c']} }
|
16
|
-
let(:numericality_options) { { only_integer: true, message: 'must be an integer' } }
|
17
|
-
|
18
|
-
let(:random_strings) do
|
19
|
-
{
|
20
|
-
matched_strings: ['abc'],
|
21
|
-
unmatched_strings: ['nqtien310@gmail.com', 'nqtien310@hotdev.com']
|
22
|
-
}
|
23
|
-
end
|
24
|
-
|
25
|
-
['presence', 'format', 'uniqueness', 'length', 'inclusion', 'exclusion', 'numericality'].each do | type |
|
26
|
-
let("#{type}_validator_class") { mock("#{type}_validator_class".to_sym, to_s: "ActiveModel::Validations::#{type.upcase}Validator") }
|
27
|
-
let("#{type}_validator".to_sym) do
|
28
|
-
mock("#{type}_validator".to_sym, :class => eval("#{type}_validator_class"),
|
29
|
-
attributes: [attribute], options: eval("#{type}_options") )
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
let(:validators) { [presence_validator, uniqueness_validator, format_validator, length_validator,
|
34
|
-
inclusion_validator, exclusion_validator, numericality_validator] }
|
35
|
-
let(:model) { mock(:model, validators: validators) }
|
36
|
-
|
37
|
-
before { RandomString.should_receive(:generate).with(/abc/).and_return(random_strings) }
|
38
|
-
|
39
|
-
let(:expected) {
|
40
|
-
[
|
41
|
-
'it { should validate_presence_of(:student) }',
|
42
|
-
'it { should validate_uniqueness_of(:student).scoped_to(:class).scoped_to(:college) }',
|
43
|
-
"it { should allow_value('abc').for(:student) }",
|
44
|
-
"it { should_not allow_value('nqtien310@gmail.com').for(:student) }",
|
45
|
-
"it { should_not allow_value('nqtien310@hotdev.com').for(:student) }",
|
46
|
-
"it { should ensure_length_of(:student).is_at_least(1).is_at_most(20) }",
|
47
|
-
"it { should ensure_inclusion_of(:student).in_range(1..20).allow_nil(true).allow_blank(true) }",
|
48
|
-
'it { should ensure_exclusion_of(:student).in_array(["a", "b", "c"]) }',
|
49
|
-
"it { should validate_numericality_of(:student).only_integer.with_message('must be an integer') }"
|
50
|
-
]
|
7
|
+
describe '#generate_validators' do
|
8
|
+
let(:validator1){ mock(:validator)}
|
9
|
+
let(:validator2){ mock(:validator)}
|
10
|
+
let(:validator3){ mock(:validator)}
|
11
|
+
let(:validator4){ mock(:validator)}
|
12
|
+
|
13
|
+
let(:validators) {
|
14
|
+
[validator1, validator2, validator3, validator4]
|
51
15
|
}
|
52
16
|
|
53
|
-
|
54
|
-
|
17
|
+
let(:model) { mock(:model, :validators => validators)}
|
18
|
+
|
19
|
+
it 'should invoke #generate_for_validator for each validator' do
|
20
|
+
should_receive(:generate_for_validator).with(validator1).and_return("it should do something")
|
21
|
+
should_receive(:generate_for_validator).with(validator2).and_return("it should do another thing")
|
22
|
+
should_receive(:generate_for_validator).with(validator3).and_return(nil)
|
23
|
+
should_receive(:generate_for_validator).with(validator4).and_return(["another thing"])
|
24
|
+
result = generate_validations(model)
|
25
|
+
result.should eq ['it should do something', 'it should do another thing', 'another thing']
|
55
26
|
end
|
56
27
|
end
|
57
28
|
|
@@ -233,8 +204,8 @@ describe 'QuickShoulda::Generator::Validation' do
|
|
233
204
|
end
|
234
205
|
|
235
206
|
context 'do not contain invalid option' do
|
236
|
-
let(:options) { {:
|
237
|
-
let(:expected) { ".
|
207
|
+
let(:options) { {:maximum=>20, :minimum=>1} }
|
208
|
+
let(:expected) { ".is_at_most(20).is_at_least(1)" }
|
238
209
|
it 'should return shoulda option methods corresponded with given options' do
|
239
210
|
send(:shoulda_option_methods_chain, options).should eq expected
|
240
211
|
end
|
@@ -263,8 +234,8 @@ describe 'QuickShoulda::Generator::Validation' do
|
|
263
234
|
|
264
235
|
context 'other types' do
|
265
236
|
let(:type) { 'length' }
|
266
|
-
let(:options) { {:
|
267
|
-
let(:expected) { ['it { should ensure_length_of(:username).
|
237
|
+
let(:options) { {:maximum=>20, :minimum=>1} }
|
238
|
+
let(:expected) { ['it { should ensure_length_of(:username).is_at_most(20).is_at_least(1) }'] }
|
268
239
|
|
269
240
|
it 'should return 1 complete shoulda test case' do
|
270
241
|
should_receive(:validation_type).at_least(1).and_return(type)
|
@@ -360,12 +331,12 @@ describe 'QuickShoulda::Generator::Validation' do
|
|
360
331
|
let(:attr) { 'email' }
|
361
332
|
let(:matched_strings) { ['123','456'] }
|
362
333
|
let(:unmatched_strings) { ['abc'] }
|
363
|
-
let(:options) { {with
|
334
|
+
let(:options) { { :with => /123|456/ } }
|
364
335
|
|
365
336
|
let(:random_strings) {
|
366
337
|
{
|
367
|
-
matched_strings
|
368
|
-
unmatched_strings
|
338
|
+
:matched_strings => matched_strings,
|
339
|
+
:unmatched_strings => unmatched_strings
|
369
340
|
}
|
370
341
|
}
|
371
342
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quick_shoulda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
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: 2013-05-
|
12
|
+
date: 2013-05-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: random_string
|
@@ -28,23 +28,23 @@ dependencies:
|
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
31
|
+
name: rspec
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
|
-
- -
|
35
|
+
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: '
|
37
|
+
version: '0'
|
38
38
|
type: :development
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: '
|
45
|
+
version: '0'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: rake
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
@@ -116,12 +116,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
116
|
- - ! '>='
|
117
117
|
- !ruby/object:Gem::Version
|
118
118
|
version: '0'
|
119
|
+
segments:
|
120
|
+
- 0
|
121
|
+
hash: -3326814885739799411
|
119
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
123
|
none: false
|
121
124
|
requirements:
|
122
125
|
- - ! '>='
|
123
126
|
- !ruby/object:Gem::Version
|
124
127
|
version: '0'
|
128
|
+
segments:
|
129
|
+
- 0
|
130
|
+
hash: -3326814885739799411
|
125
131
|
requirements: []
|
126
132
|
rubyforge_project:
|
127
133
|
rubygems_version: 1.8.25
|