morse_spec_helpers 0.0.8 → 0.0.9

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: 397428c18045d1bfc254e55fda1e7f753fd12d08
4
- data.tar.gz: 990307e6a603cbacf4d4e6d992e0907d3420a393
3
+ metadata.gz: 757ac30270b0e40c39e04e69d6319476329b0429
4
+ data.tar.gz: d78da6063c640d5e2e95dbc3bbdebbc8ae125c3b
5
5
  SHA512:
6
- metadata.gz: 352c0241e6b2a0f8a6fd70997650382b39c470fd349798e1bf5da5872487c710b064bc7d51d134f0d325a5fd8d347a14f9ca08d017aa0cde5fe521c2381b63a2
7
- data.tar.gz: d8dfcd62c0cdeb96369b24e42780409cd076099035fa41030d2f60ca7ff6c8a51d6e115023f8c3026a3a9a1ee932d7a1b4df9522fb995d7db774acfa4359264c
6
+ metadata.gz: a5309a9b65b89df37196b44a52e32bf19e9ce17ad9006cafea8c4a3e5b581be6e33358da91be734f7694c09f42b7d51c41dc2cad0feaa388d3ed1ad1c5075429
7
+ data.tar.gz: 7e33f8bbe49c4f1850ef7af4619ccf0d61ad13591986660265304bfb35cf2afd6efc70c7063dd3f089c0a0570c42f4be65f7d720fdfd0b532a6ba2719894e3cd
@@ -5,7 +5,8 @@ class MorseSpecHelpersGenerator < Rails::Generators::Base
5
5
  image_dir="#{support_dir}/images"
6
6
  Dir.mkdir(support_dir) unless Dir.exist?(support_dir)
7
7
  Dir.mkdir(image_dir) unless Dir.exist?(image_dir)
8
- copy_file '../support/project_helpers.rb',"#{support_dir}/project/helpers.rb"
8
+ copy_file '../support/project_helpers.rb',"#{support_dir}/project_helpers.rb"
9
9
  copy_file '../support/images/placeholder.png',"#{image_dir}/placeholder.png"
10
+ copy_file '../initializers/morse.rb',"#{Rails.root}/config/initializers/morse.rb"
10
11
  end
11
12
  end
@@ -0,0 +1,90 @@
1
+ class ActiveRecord::Base
2
+
3
+ def associated_object_exists(klass,fn,required=true)
4
+ id=self.send(fn)
5
+ id_setter=(fn.to_s+'=').to_sym
6
+ unless klass.find_by_id(id)
7
+ self.send(id_setter,nil)
8
+ id=nil
9
+ end
10
+ if required==true and id.nil?
11
+ errors.add(fn,"does not exist")
12
+ return false
13
+ end
14
+ end
15
+
16
+ def blank_to_nil(thing)
17
+ if self.send(thing).blank?
18
+ self.send(thing.to_s+'=',nil)
19
+ end
20
+ end
21
+
22
+ def process_attachment(options={})
23
+ options={:model_name=>:asset, :uploader_name=>:attachment}.merge(options)
24
+ model_name=options[:model_name]
25
+ uploader_name=options[:uploader_name]
26
+ klass=eval(model_name.to_s.camelize)
27
+ if self.send(uploader_name)
28
+ a=klass.new(uploader_name=>self.send(uploader_name))
29
+ if a.save
30
+ self.send(model_name,a)
31
+ self.send(uploader_name,nil)
32
+ save
33
+ else
34
+ errors.add(uploader_name,'had a problem saving')
35
+ end
36
+ end
37
+ if klass.find_by_id(self.id)
38
+ self.reload
39
+ end
40
+ end
41
+
42
+ def survive_if(thing)
43
+ if self.send(thing)==true
44
+ errors.add(:base,"Cannot destroy while #{thing} is true")
45
+ false
46
+ elsif self.send(thing).is_a?(Array) and self.send(thing).any?
47
+ errors.add(:base,"Cannot destroy while #{thing} has members")
48
+ false
49
+ end
50
+ end
51
+
52
+ def there_can_be_only_one(thing)
53
+ if new_record?
54
+ enemies=self.class.where("#{thing} = ?",true)
55
+ else
56
+ enemies=self.class.where("#{thing} = ? and id != ? ",true,id)
57
+ end
58
+ if enemies.any?
59
+ enemies.each do |e|
60
+ e.default_land=false
61
+ e.save
62
+ end
63
+ end
64
+ end
65
+
66
+ def there_must_be_one(thing)
67
+ existing=self.class.where("#{thing} = ?",true)
68
+ if existing.empty?
69
+ self.send("#{thing}=",true)
70
+ end
71
+ end
72
+
73
+ def validate_integer_or_default(thing,default)
74
+ unless self.send(thing)
75
+ self.send("#{thing}=",default)
76
+ end
77
+ end
78
+
79
+ def validate_mandatory_boolean(thing,message="must be true")
80
+ unless self.send(thing)==true
81
+ errors.add(thing,message)
82
+ end
83
+ end
84
+ end
85
+
86
+ #class Array
87
+ # def sum
88
+ # inject( nil ) { |sum,x| sum ? sum+x : x }
89
+ # end
90
+ #end
@@ -1,3 +1,3 @@
1
1
  module MorseSpecHelpers
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: morse_spec_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Terry S
@@ -52,6 +52,7 @@ files:
52
52
  - Rakefile
53
53
  - lib/generators/morse_spec_helpers_generator.rb
54
54
  - lib/generators/support_generator.rb
55
+ - lib/initializers/morse.rb
55
56
  - lib/morse_spec_helpers.rb
56
57
  - lib/morse_spec_helpers/version.rb
57
58
  - lib/support/images/placeholder.png