sandwich 0.0.12 → 0.0.13

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.12
1
+ 0.0.13
@@ -2,7 +2,7 @@ require 'sandwich/ext/string'
2
2
 
3
3
  Given /^((?:an?|the|\d+) .+)$/ do |what| end
4
4
 
5
- Transform /(?:an?|\d+) .+/ do |match|
5
+ Transform /(?:an?|\d+|the) .+/ do |match|
6
6
  materialize!(match)
7
7
  end
8
8
 
@@ -10,10 +10,6 @@ Given /^(an?|the|\d+) (.+) with the following attributes:$/ do |total, what, tab
10
10
  total.times { record!(what, table.rows_hash) }
11
11
  end
12
12
 
13
- Transform /the (.+?) "([^\"]*)"$/ do |what, value|
14
- record(what, value)
15
- end
16
-
17
13
  Given /^(.+) belong(?:ing|s) to (an?|the) (.+)$/ do |child, determiner, rest|
18
14
  d = definition("#{determiner} #{rest}")
19
15
  a = child.class.reflect_on_association(d.raw_model.underscore.to_sym)
@@ -10,3 +10,7 @@ end
10
10
  Then /^I should see #{qc} in the (\w+) data row of (.+)$/ do |value, ordinal, path|
11
11
  page.should have_xpath("(#{xpath(selector_for(path))}//tr[td])[#{ordinal.to_i}]", :text => value)
12
12
  end
13
+
14
+ Then /^I should see (\d+) entr(?:y|ies) in ([^\"]+)$/ do |total, path|
15
+ page.should have_xpath("#{xpath(selector_for(path))}//tr[td]", :count => total.to_i)
16
+ end
@@ -1,6 +1,8 @@
1
1
  require 'strscan'
2
2
 
3
3
  module Sandwich
4
+ class ModelNotFoundError < StandardError; end
5
+
4
6
  class DefinitionScanner < StringScanner
5
7
  def initialize(str, attribute_separators)
6
8
  super
@@ -142,6 +144,8 @@ module Sandwich
142
144
  else
143
145
  record(model, values)
144
146
  end
147
+ rescue ModelNotFoundError
148
+ return match
145
149
  end
146
150
 
147
151
  def definition(str)
@@ -33,45 +33,33 @@ module Sandwich
33
33
  end
34
34
 
35
35
  def initialize(key, model)
36
- @key, @model = key, model
36
+ @key, @model = if (key.to_s == model.name.underscore)
37
+ [:master, model]
38
+ else
39
+ [key, model]
40
+ end
37
41
  end
38
42
 
39
43
  def get(args)
40
- args = prepare_args(args)
41
-
42
- result = case args
43
- when Hash
44
- @model.find(:first, :conditions => args)
45
- else
46
- @model.find(:first, :conditions => @model.default_attribute_args(args, :find))
47
- end
48
-
49
- raise "Could not find model for args: #{args.inspect}" if result.nil?
50
-
51
- result
44
+ @model.find(:first, :conditions => prepare_args(args, :find)).tap do |result|
45
+ raise "Could not find model for args: #{args.inspect}" if result.nil?
46
+ end
52
47
  end
53
48
 
54
49
  def create(args = nil)
55
- args = prepare_args(args)
56
-
57
- case args
58
- when Hash
59
- @model.make(@key, args)
60
- else
61
- @model.make(@key, @model.default_attribute_args(args, :create))
62
- end
50
+ @model.make(@key, prepare_args(args, :create))
63
51
  end
64
52
 
65
53
  private
66
54
 
67
- def prepare_args(args)
55
+ def prepare_args(args, op)
68
56
  case args
69
57
  when Hash
70
58
  Hash[*args.each_pair.map { |k, v| [k.underscore, prepare_value(k, v)] }.flatten]
71
59
  when nil
72
60
  {}
73
61
  else
74
- args
62
+ @model.default_attribute_args(args, op)
75
63
  end
76
64
  end
77
65
 
@@ -103,7 +91,7 @@ module Sandwich
103
91
  def record!(name, args)
104
92
  materializer = Materializer[name]
105
93
 
106
- return name if materializer.nil?
94
+ raise ModelNotFoundError, "No model found for '#{name}'" if materializer.nil?
107
95
 
108
96
  materializer.create(args)
109
97
  end
@@ -111,7 +99,7 @@ module Sandwich
111
99
  def record(name, args)
112
100
  materializer = Materializer[name]
113
101
 
114
- return name if materializer.nil?
102
+ raise ModelNotFoundError, "No model found for '#{name}'" if materializer.nil?
115
103
 
116
104
  materializer.get(args)
117
105
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 12
9
- version: 0.0.12
8
+ - 13
9
+ version: 0.0.13
10
10
  platform: ruby
11
11
  authors:
12
12
  - David Leal
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-06 00:00:00 +01:00
17
+ date: 2010-05-11 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency