lardawge-rfm 1.4.1.1 → 1.4.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rfm/record.rb CHANGED
@@ -189,31 +189,28 @@ module Rfm
189
189
  #
190
190
  # When you do, the change is noted, but *the data is not updated in FileMaker*. You must call
191
191
  # Record::save or Record::save_if_not_modified to actually save the data.
192
- def []=(pname, value)
193
- return super unless @loaded # keeps us from getting mods during initialization
194
- name = pname
195
- if self[name] != nil
196
- @mods[name] = val
197
- else
198
- raise Rfm::Error::ParameterError.new("You attempted to modify a field called '#{name}' on the Rfm::Record object, but that field does not exist.")
199
- end
200
- end
201
-
202
- def method_missing (symbol, *attrs)
203
- # check for simple getter
204
- return self[symbol.to_s] if self.include?(symbol.to_s)
205
-
206
- # check for setter
207
- symbol_name = symbol.to_s
208
- if symbol_name[-1..-1] == '=' && self.has_key?(symbol_name[0..-2])
209
- return @mods[symbol_name[0..-2]] = attrs[0]
210
- end
211
- super
192
+ def []=(name, value)
193
+ return super unless @loaded
194
+ raise Rfm::ParameterError, "You attempted to modify a field does not exist." unless self[name]
195
+ @mods[name] = value
212
196
  end
213
197
 
214
198
  def respond_to?(symbol, include_private = false)
215
- return true if self[symbol.to_s] != nil
199
+ return true if self[symbol.to_s]
216
200
  super
217
201
  end
202
+
203
+ private
204
+
205
+ def method_missing (symbol, *attrs, &block)
206
+ method = symbol.to_s
207
+ return self[method] if self.include?(method)
208
+
209
+ if method =~ /(=)$/ && self.has_key?($`)
210
+ return @mods[$`] = attrs.first
211
+ end
212
+ super
213
+ end
214
+
218
215
  end
219
216
  end
@@ -1,69 +1,64 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- module Rfm
4
- err_module = Error
5
- describe err_module do
6
- describe ".lookup" do
7
-
8
- it "should return a default system error if input code is 0" do
9
- error = err_module.getError(0)
10
- error.message.should eql('SystemError occurred: (FileMaker Error #0)')
11
- error.code.should eql(0)
12
- end
13
-
14
- it "should return a default system error if input code is 22" do
15
- error = err_module.getError(20)
16
- error.message.should eql('SystemError occurred: (FileMaker Error #20)')
17
- error.code.should eql(20)
18
- end
19
-
20
- it "should return a custom message as second argument" do
21
- error = err_module.getError(104, 'Custom Message Here.')
22
- error.message.should match(/Custom Message Here/)
23
- end
1
+ describe err_module = Rfm::Error do
2
+ describe ".lookup" do
24
3
 
25
- it "should return a script missing error" do
26
- error = err_module.getError(104)
27
- error.message.should eql('ScriptMissingError occurred: (FileMaker Error #104)')
28
- error.code.should eql(104)
29
- end
30
-
31
- it "should return a range validation error" do
32
- error = err_module.getError(503)
33
- error.message.should eql('RangeValidationError occurred: (FileMaker Error #503)')
34
- error.code.should eql(503)
35
- end
36
-
37
- it "should return unknown error if code not found" do
38
- error = err_module.getError(-1)
39
- error.message.should eql('UnknownError occurred: (FileMaker Error #-1)')
40
- error.code.should eql(-1)
41
- error.class.should eql(Error::UnknownError)
42
- end
43
-
4
+ it "should return a default system error if input code is 0" do
5
+ error = err_module.getError(0)
6
+ error.message.should eql('SystemError occurred: (FileMaker Error #0)')
7
+ error.code.should eql(0)
44
8
  end
45
9
 
46
- describe ".find_by_code" do
47
- it "should return a constant representing the error class" do
48
- constant = err_module.find_by_code(503)
49
- constant.should eql(err_module::RangeValidationError)
50
- end
10
+ it "should return a default system error if input code is 22" do
11
+ error = err_module.getError(20)
12
+ error.message.should eql('SystemError occurred: (FileMaker Error #20)')
13
+ error.code.should eql(20)
51
14
  end
52
15
 
53
- describe ".build_message" do
54
- before(:each) do
55
- @message = err_module.build_message(503, 'This is a custom message')
56
- end
57
-
58
- it "should return a string with the code and message included" do
59
- @message.should match(/This is a custom message/)
60
- @message.should match(/503/)
61
- end
62
-
63
- it "should look like" do
64
- @message.should eql('503 occurred: (FileMaker Error #This is a custom message)')
65
- end
16
+ it "should return a custom message as second argument" do
17
+ error = err_module.getError(104, 'Custom Message Here.')
18
+ error.message.should match(/Custom Message Here/)
66
19
  end
20
+
21
+ it "should return a script missing error" do
22
+ error = err_module.getError(104)
23
+ error.message.should eql('ScriptMissingError occurred: (FileMaker Error #104)')
24
+ error.code.should eql(104)
25
+ end
67
26
 
27
+ it "should return a range validation error" do
28
+ error = err_module.getError(503)
29
+ error.message.should eql('RangeValidationError occurred: (FileMaker Error #503)')
30
+ error.code.should eql(503)
31
+ end
32
+
33
+ it "should return unknown error if code not found" do
34
+ error = err_module.getError(-1)
35
+ error.message.should eql('UnknownError occurred: (FileMaker Error #-1)')
36
+ error.code.should eql(-1)
37
+ error.class.should eql(err_module::UnknownError)
38
+ end
39
+
40
+ end
41
+
42
+ describe ".find_by_code" do
43
+ it "should return a constant representing the error class" do
44
+ constant = err_module.find_by_code(503)
45
+ constant.should eql(err_module::RangeValidationError)
46
+ end
47
+ end
48
+
49
+ describe ".build_message" do
50
+ before(:each) do
51
+ @message = err_module.build_message(503, 'This is a custom message')
52
+ end
53
+
54
+ it "should return a string with the code and message included" do
55
+ @message.should match(/This is a custom message/)
56
+ @message.should match(/503/)
57
+ end
58
+
59
+ it "should look like" do
60
+ @message.should eql('503 occurred: (FileMaker Error #This is a custom message)')
61
+ end
68
62
  end
63
+
69
64
  end
@@ -0,0 +1,83 @@
1
+ require 'rfm/record'
2
+ describe Rfm::Record do
3
+ before(:each) do
4
+ @record = Rfm::Record.allocate
5
+ end
6
+
7
+ describe "#[]=" do
8
+ before(:each) do
9
+ @record.instance_variable_set(:@mods, {})
10
+ @record.instance_variable_set(:@loaded, false)
11
+ @record['tester'] = 'red'
12
+ end
13
+
14
+ it "creates a new hash key => value upon instantiation of record" do
15
+ @record.has_key?('tester').should be_true
16
+ @record['tester'].should eql('red')
17
+ end
18
+
19
+ it "creates a new hash key => value in @mods when modifying an existing record key" do
20
+ @record.instance_variable_set(:@loaded, true)
21
+ @record['tester'] = 'green'
22
+
23
+ @record.instance_variable_get(:@mods).has_key?('tester').should be_true
24
+ @record.instance_variable_get(:@mods)['tester'].should eql('green')
25
+ end
26
+
27
+ it "raises an Rfm::ParameterError if a key is used that does not exist" do
28
+ @record.instance_variable_set(:@loaded, true)
29
+
30
+ ex = rescue_from { @record['tester2'] = 'error' }
31
+ ex.class.should eql(Rfm::ParameterError)
32
+ ex.message.should eql('You attempted to modify a field does not exist.')
33
+ end
34
+
35
+ end
36
+
37
+ describe "#respond_to?" do
38
+ it "returns true if key is in hash" do
39
+ @record['red'] = 'stop'
40
+
41
+ @record.respond_to?(:red).should be_true
42
+ end
43
+
44
+ it "returns false if key is not in hash" do
45
+ @record.respond_to?(:red).should be_false
46
+ end
47
+ end
48
+
49
+ describe "#method_missing" do
50
+ before(:each) do
51
+ @record.instance_variable_set(:@mods, {})
52
+ @record['name'] = 'red'
53
+ end
54
+
55
+ describe "getter" do
56
+ it "will match a method to key in the hash if there is one" do
57
+ @record.name.should eql('red')
58
+ end
59
+
60
+ it "will raise NoMethodError if no key present that matches value" do
61
+ ex = rescue_from { @record.namee }
62
+ ex.class.should eql(NoMethodError)
63
+ ex.message.should match(/undefined method `namee'/)
64
+ end
65
+ end
66
+
67
+ describe "setter" do
68
+ it "acts as a setter if the key exists in the hash" do
69
+ @record.name = 'blue'
70
+
71
+ @record.instance_variable_get(:@mods).has_key?('name').should be_true
72
+ @record.instance_variable_get(:@mods)['name'].should eql('blue')
73
+ end
74
+
75
+ it "will raise NoMethodError if no key present that matches value" do
76
+ ex = rescue_from { @record.namee = 'red' }
77
+ ex.class.should eql(NoMethodError)
78
+ ex.message.should match(/undefined method `namee='/)
79
+ end
80
+ end
81
+
82
+ end
83
+ end
data/spec/spec_helper.rb CHANGED
@@ -5,5 +5,14 @@ require 'spec'
5
5
  require 'spec/autorun'
6
6
 
7
7
  Spec::Runner.configure do |config|
8
-
8
+ end
9
+
10
+ def rescue_from(&block)
11
+ exception = nil
12
+ begin
13
+ yield
14
+ rescue StandardError => e
15
+ exception = e
16
+ end
17
+ exception
9
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lardawge-rfm
3
3
  version: !ruby/object:Gem::Version
4
- hash: 121
4
+ hash: 127
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 4
9
9
  - 1
10
- - 1
11
- version: 1.4.1.1
10
+ - 2
11
+ version: 1.4.1.2
12
12
  platform: ruby
13
13
  authors:
14
14
  - Geoff Coffey
@@ -19,7 +19,7 @@ autorequire:
19
19
  bindir: bin
20
20
  cert_chain: []
21
21
 
22
- date: 2010-07-03 00:00:00 -07:00
22
+ date: 2010-07-09 00:00:00 -07:00
23
23
  default_executable:
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency
@@ -60,6 +60,7 @@ files:
60
60
  - LICENSE
61
61
  - README.rdoc
62
62
  - spec/rfm/error_spec.rb
63
+ - spec/rfm/record_spec.rb
63
64
  - spec/spec_helper.rb
64
65
  has_rdoc: true
65
66
  homepage: http://sixfriedrice.com/wp/products/rfm/
@@ -99,4 +100,5 @@ specification_version: 3
99
100
  summary: Ruby to Filemaker adapter
100
101
  test_files:
101
102
  - spec/rfm/error_spec.rb
103
+ - spec/rfm/record_spec.rb
102
104
  - spec/spec_helper.rb