lucid_works 0.6.7 → 0.6.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -49,6 +49,16 @@ module LucidWorks
49
49
  attr_accessor :collection_name # :nodoc:
50
50
  attr_accessor_with_default :singleton, false
51
51
 
52
+ def model_name
53
+ super.tap do |name|
54
+ name.instance_eval do
55
+ def singular; ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(self)).tr('/', '_').freeze; end
56
+ def plural; singular.pluralize.freeze; end
57
+ def collection; ActiveSupport::Inflector.tableize(ActiveSupport::Inflector.demodulize(self)).freeze; end
58
+ end
59
+ end
60
+ end
61
+
52
62
  # The attributes for a model are ascertained in on of two ways.
53
63
  # Without a schema, the attributes list is automatically generated when the the object is retrieved from the server.
54
64
  # Alternatively, you may define a schema for your object.
@@ -105,9 +105,11 @@ module LucidWorks
105
105
  #
106
106
  def schedule=(all_attributes)
107
107
  # convert to format accepted by Time.advance
108
- all_attributes['start'].to_options!
109
- all_attributes['start'].each{|k,v| all_attributes['start'][k]=v.to_i}
110
-
108
+ if all_attributes['start']
109
+ all_attributes['start'].to_options!
110
+ all_attributes['start'].each{|k,v| all_attributes['start'][k]=v.to_i}
111
+ end
112
+
111
113
  self.active = all_attributes['active'] if all_attributes.keys.include?('active')
112
114
 
113
115
  self.frequency = all_attributes['frequency']
@@ -161,12 +163,21 @@ module LucidWorks
161
163
  # convenience method for detecting whether schedule can be represented in simple format
162
164
  # or should be described as custom (meaning it is beyond the capabilities of the convenience methods)
163
165
  #
164
- def custom?
165
- return true if self.frequency == 'custom'
166
- return false unless self.start_time
167
- return true if self.start_is_more_than_one_period_in_the_future?
168
- return false
166
+ def custom?
167
+ return true if self.frequency == 'custom'
168
+ return false unless self.start_time
169
+ return true if self.start_is_more_than_one_period_in_the_future?
170
+ return false
171
+ end
172
+
173
+ #
174
+ # convenience method for setting defaults in a UI that make sense for a user
175
+ #
176
+ def ui_appropriate_defaults!
177
+ if self.start_time.blank? || self.period == 0
178
+ self.active = true
169
179
  end
180
+ end
170
181
  end
171
182
  end
172
183
  end
@@ -1,3 +1,3 @@
1
1
  module LucidWorks
2
- VERSION = "0.6.7"
2
+ VERSION = "0.6.8"
3
3
  end
@@ -35,6 +35,42 @@ describe LucidWorks::Base do
35
35
  end
36
36
  end
37
37
 
38
+ describe "naming support" do
39
+ context "for a namespaced model" do
40
+ class LucidWorks::NamespacedModel < LucidWorks::Base
41
+ end
42
+
43
+ it "demodulizes the model's singular name" do
44
+ LucidWorks::NamespacedModel.model_name.singular.should == "namespaced_model"
45
+ end
46
+
47
+ it "demodulizes the model's plural name" do
48
+ LucidWorks::NamespacedModel.model_name.plural.should == "namespaced_models"
49
+ end
50
+
51
+ it "demodulizes the model's collection name" do
52
+ LucidWorks::NamespacedModel.model_name.collection.should == "namespaced_models"
53
+ end
54
+ end
55
+
56
+ context "for a top-level model" do
57
+ class TopLevelModel < LucidWorks::Base
58
+ end
59
+
60
+ it "returns the model's singular name" do
61
+ TopLevelModel.model_name.singular.should == "top_level_model"
62
+ end
63
+
64
+ it "returns the model's plural name" do
65
+ TopLevelModel.model_name.plural.should == "top_level_models"
66
+ end
67
+
68
+ it "returns the model's collection name" do
69
+ TopLevelModel.model_name.plural.should == "top_level_models"
70
+ end
71
+ end
72
+ end
73
+
38
74
  describe "class methods" do
39
75
 
40
76
  describe ".schema" do
@@ -345,4 +345,26 @@ describe LucidWorks::Datasource::Schedule do
345
345
  @schedule.should_not be_custom
346
346
  end
347
347
  end
348
+
349
+ describe '#ui_appropriate_defaults!' do
350
+ it "should set active to true if start_time is defaulted" do
351
+ @schedule.start_time = nil
352
+ @schedule.period = 1.hours.seconds
353
+ @schedule.active = false
354
+
355
+ @schedule.ui_appropriate_defaults!
356
+
357
+ @schedule.active.should == true
358
+ end
359
+
360
+ it "should set active to true if period is defaulted" do
361
+ @schedule.start_time = Time.now
362
+ @schedule.period = 0
363
+ @schedule.active = false
364
+
365
+ @schedule.ui_appropriate_defaults!
366
+
367
+ @schedule.active.should == true
368
+ end
369
+ end
348
370
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: lucid_works
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.6.7
5
+ version: 0.6.8
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sam Pierson
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-18 00:00:00 -04:00
13
+ date: 2011-05-19 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency