quick_shoulda 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.rspec CHANGED
@@ -1,4 +1,3 @@
1
1
  --color
2
- --debug
3
2
  -f documentation
4
3
  -p
data/.travis.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - "1.8.7"
3
4
  - "1.9.2"
4
5
  - "1.9.3"
5
6
  # uncomment this line if your project needs to run something other than `rake`:
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
@@ -11,7 +11,8 @@ module QuickShoulda
11
11
  elsif value.is_a? Symbol
12
12
  "(:#{value})"
13
13
  else
14
- "(#{value})"
14
+ #fix for 1.8.7
15
+ "(#{value.inspect})"
15
16
  end
16
17
  end
17
18
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module QuickShoulda
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -20,6 +20,6 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ["lib"]
21
21
 
22
22
  spec.add_dependency "random_string"
23
- spec.add_development_dependency "debugger", "~> 1.3"
24
23
  spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "rake"
25
25
  end
@@ -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 '#generate' do
8
- let(:attribute) { :student }
9
-
10
- let(:presence_options) { {} }
11
- let(:uniqueness_options) { { scope: [:class, :college]} }
12
- let(:format_options) { { with: /abc/} }
13
- let(:length_options) { { minimum: 1, maximum: 20}}
14
- let(:inclusion_options) { { within: (1..20), :allow_nil => true, :allow_blank => true} }
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
- it 'should return exact array of strings' do
54
- generate_validations(model).should eq expected
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) { {:minimum=>1, :maximum=>20} }
237
- let(:expected) { ".is_at_least(1).is_at_most(20)" }
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) { {:minimum=>1, :maximum=>20} }
267
- let(:expected) { ['it { should ensure_length_of(:username).is_at_least(1).is_at_most(20) }'] }
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: /123|456/ } }
334
+ let(:options) { { :with => /123|456/ } }
364
335
 
365
336
  let(:random_strings) {
366
337
  {
367
- matched_strings: matched_strings,
368
- unmatched_strings: 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.0
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-01 00:00:00.000000000 Z
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: debugger
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: '1.3'
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: '1.3'
45
+ version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
- name: rspec
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