sandwich 0.0.19 → 0.0.20
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 +1 -1
- data/lib/sandwich/cucumber/web_steps.rb +14 -2
- data/lib/sandwich/helpers/base.rb +25 -0
- data/lib/sandwich/model/base.rb +1 -1
- data/lib/sandwich/model/definition_scanner.rb +1 -1
- data/lib/sandwich/model/machinist.rb +3 -3
- data/lib/sandwich/model/materializer.rb +1 -22
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.20
|
@@ -8,7 +8,7 @@ end
|
|
8
8
|
|
9
9
|
World(Sandwich::WithinHelper)
|
10
10
|
|
11
|
-
Given /^I(
|
11
|
+
Given /^I(?:\'m| am) on the page for (.+)$/ do |record|
|
12
12
|
visit(polymorphic_path(record))
|
13
13
|
end
|
14
14
|
|
@@ -28,6 +28,14 @@ Then /^I should see "([^\"]*)" (?:with)?in (.+)$/ do |text, selector|
|
|
28
28
|
page.should have_xpath(xpath(selector_for(selector)), :text => text)
|
29
29
|
end
|
30
30
|
|
31
|
+
Then /^I should not see "([^\"]*)" (?:with)?in (.+)$/ do |text, selector|
|
32
|
+
page.should_not have_xpath(xpath(selector_for(selector)), :text => text)
|
33
|
+
end
|
34
|
+
|
35
|
+
Then /^I (should|should not) see a link to "([^\"]+)"/ do |action, text|
|
36
|
+
page.send(action.underscore, have_xpath("//a", :text => text))
|
37
|
+
end
|
38
|
+
|
31
39
|
Then /^I should see the header "([^\"]*)"$/ do |text|
|
32
40
|
page.should have_xpath("//h1 | //h2 | //h3 | //h4 | //h5 | //h6")
|
33
41
|
end
|
@@ -37,7 +45,11 @@ Then /^I should see the (notice|error) "([^\"]*)"$/ do |type, message|
|
|
37
45
|
end
|
38
46
|
|
39
47
|
Then /^I should see (.+)$/ do |selector|
|
40
|
-
|
48
|
+
page.should have_xpath(xpath(selector_for(selector)))
|
49
|
+
end
|
50
|
+
|
51
|
+
Then /^I should not see (.+)$/ do |selector|
|
52
|
+
page.should_not have_xpath(xpath(selector_for(selector)))
|
41
53
|
end
|
42
54
|
|
43
55
|
When /^I fill in the following:$/ do |table|
|
@@ -27,6 +27,31 @@ module Sandwich
|
|
27
27
|
raise "No default attribute defined for #{self}"
|
28
28
|
end
|
29
29
|
end
|
30
|
+
|
31
|
+
def prepare_args(args, op)
|
32
|
+
case args
|
33
|
+
when Hash
|
34
|
+
Hash[*args.each_pair.map { |k, v| prepare_pair(k, v) }.flatten]
|
35
|
+
when nil
|
36
|
+
{}
|
37
|
+
else
|
38
|
+
default_attribute_args(args, op)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def prepare_pair(k, v)
|
45
|
+
[k.underscore, prepare_value(k, v)]
|
46
|
+
end
|
47
|
+
|
48
|
+
def prepare_value(key, value)
|
49
|
+
if assoc = reflect_on_association(key.to_sym)
|
50
|
+
Sandwich::Model::Materializer[assoc.class_name].get(value)
|
51
|
+
else
|
52
|
+
value
|
53
|
+
end
|
54
|
+
end
|
30
55
|
end
|
31
56
|
end
|
32
57
|
end
|
data/lib/sandwich/model/base.rb
CHANGED
@@ -7,7 +7,7 @@ module Sandwich
|
|
7
7
|
|
8
8
|
class Materializer < Sandwich::Model::Materializer
|
9
9
|
def new(args = nil)
|
10
|
-
@model.make_unsaved(@key, prepare_args(args, :create))
|
10
|
+
@model.make_unsaved(@key, @model.prepare_args(args, :create))
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -19,8 +19,8 @@ module Sandwich
|
|
19
19
|
include Sandwich::Model::Base::Extensions
|
20
20
|
|
21
21
|
def blueprint(name = :master, &blueprints)
|
22
|
-
if block_given?
|
23
|
-
Machinist::Materializer[name] = self
|
22
|
+
if block_given? && name != :master
|
23
|
+
Machinist::Materializer[name] = self
|
24
24
|
end
|
25
25
|
|
26
26
|
super
|
@@ -37,31 +37,10 @@ module Sandwich
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def get(args)
|
40
|
-
@model.find(:first, :conditions => prepare_args(args, :find)).tap do |result|
|
40
|
+
@model.find(:first, :conditions => @model.prepare_args(args, :find)).tap do |result|
|
41
41
|
raise "Could not find model for args: #{args.inspect}" if result.nil?
|
42
42
|
end
|
43
43
|
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def prepare_args(args, op)
|
48
|
-
case args
|
49
|
-
when Hash
|
50
|
-
Hash[*args.each_pair.map { |k, v| [k.underscore, prepare_value(k, v)] }.flatten]
|
51
|
-
when nil
|
52
|
-
{}
|
53
|
-
else
|
54
|
-
@model.default_attribute_args(args, op)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def prepare_value(key, value)
|
59
|
-
if assoc = @model.reflect_on_association(key.to_sym)
|
60
|
-
self.class[assoc.class_name].get(value)
|
61
|
-
else
|
62
|
-
value
|
63
|
-
end
|
64
|
-
end
|
65
44
|
end
|
66
45
|
end
|
67
46
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 20
|
9
|
+
version: 0.0.20
|
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-06-
|
17
|
+
date: 2010-06-12 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|