amrita2 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/init.rb +1 -0
- data/lib/amrita2/rails_bridge.rb +92 -7
- data/lib/amrita2/template.rb +12 -127
- data/lib/amrita2/testsupport.rb +0 -25
- data/lib/amrita2/version.rb +1 -1
- data/sample/depot/app/controllers/admin_controller.rb +3 -1
- data/sample/depot/app/helpers/cart_helper.rb +8 -0
- data/sample/depot/app/helpers/price_helper.rb +7 -0
- data/sample/depot/config/environment.rb +0 -14
- data/sample/depot/config/environments/development.rb +2 -2
- data/sample/depot/db/schema.rb +27 -20
- data/sample/depot/test/functional/admin_controller_test.rb +63 -22
- data/sample/depot/test/functional/store_controller_test.rb +30 -18
- data/sample/depot/vendor/plugins/will_paginate/init.rb +4 -0
- data/sample/depot/vendor/plugins/will_paginate/lib/will_paginate.rb +61 -0
- data/sample/depot/vendor/plugins/will_paginate/lib/will_paginate/collection.rb +132 -0
- data/sample/depot/vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb +80 -0
- data/sample/depot/vendor/plugins/will_paginate/lib/will_paginate/finder.rb +181 -0
- data/sample/depot/vendor/plugins/will_paginate/lib/will_paginate/view_helpers.rb +206 -0
- data/sample/depot/vendor/plugins/will_paginate/test/array_pagination_test.rb +131 -0
- data/sample/depot/vendor/plugins/will_paginate/test/boot.rb +23 -0
- data/sample/depot/vendor/plugins/will_paginate/test/finder_test.rb +290 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/admin.rb +3 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/company.rb +9 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/developer.rb +11 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/project.rb +15 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/reply.rb +5 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/schema.rb +38 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/topic.rb +4 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/user.rb +2 -0
- data/sample/depot/vendor/plugins/will_paginate/test/helper.rb +25 -0
- data/sample/depot/vendor/plugins/will_paginate/test/lib/activerecord_test_case.rb +23 -0
- data/sample/depot/vendor/plugins/will_paginate/test/lib/activerecord_test_connector.rb +67 -0
- data/sample/depot/vendor/plugins/will_paginate/test/lib/load_fixtures.rb +13 -0
- data/sample/depot/vendor/plugins/will_paginate/test/pagination_test.rb +240 -0
- data/sample/hello/test1.rb +23 -0
- data/sample/login_engine/config/environment.rb +18 -20
- data/sample/login_engine/config/environments/development.rb +2 -2
- data/sample/login_engine/db/schema.rb +24 -17
- data/sample/login_engine/lib/login_engine/authenticated_system.rb +18 -18
- data/sample/login_engine/test/functional/user_controller_test.rb +1 -0
- data/sample/ramaze/ramaise_amrita2.rb +156 -0
- data/specs/attribute.rb +11 -0
- data/specs/datatypes.rb +13 -0
- data/specs/sample.rb +1 -2
- data/specs/sanitize.rb +14 -0
- metadata +28 -7
- data/sample/depot/app/helpers/ar_form.rb +0 -169
- data/sample/depot/app/helpers/form_tag.rb +0 -24
- data/sample/depot/app/helpers/standard_form.rb +0 -73
- data/sample/depot/test/integration/dsl_user_stories_test.rb +0 -126
- data/sample/depot/test/integration/user_stories_test.rb +0 -70
data/specs/sample.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
|
2
1
|
require 'amrita2'
|
3
2
|
require 'amrita2/testsupport'
|
4
3
|
|
5
4
|
module SampleTestSupport
|
6
5
|
def get_result(dir, fname)
|
7
6
|
Dir::chdir("sample/#{dir}") do
|
8
|
-
IO.popen("ruby -I../../lib #{fname}") do |f|
|
7
|
+
IO.popen("ruby -rubygems -I../../lib #{fname}") do |f|
|
9
8
|
f.read
|
10
9
|
end
|
11
10
|
end
|
data/specs/sanitize.rb
CHANGED
@@ -61,6 +61,20 @@ include Amrita2
|
|
61
61
|
result.should_be_samexml_as(expected)
|
62
62
|
end
|
63
63
|
end
|
64
|
+
|
65
|
+
specify "do sanitize double quotes" do
|
66
|
+
data = {
|
67
|
+
:aaa=> {
|
68
|
+
:href=>'http://www.ruby-lang.org/',
|
69
|
+
:title=>"\"Ruby's home page\"",
|
70
|
+
:body=>'<Ruby>'
|
71
|
+
}
|
72
|
+
}
|
73
|
+
expected = %[<a href="http://www.ruby-lang.org/" title=""Ruby's home page""><Ruby></a>]
|
74
|
+
@t.test_with(data) do |result|
|
75
|
+
result.should_be_samexml_as(expected)
|
76
|
+
end
|
77
|
+
end
|
64
78
|
|
65
79
|
specify "stop sanitize" do
|
66
80
|
data = {
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: amrita2
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 2.0.
|
7
|
-
date: 2008-
|
6
|
+
version: 2.0.1
|
7
|
+
date: 2008-02-07 00:00:00 +09:00
|
8
8
|
summary: Amrita2 is a a xml/xhtml template library for Ruby
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -88,12 +88,11 @@ files:
|
|
88
88
|
- sample/login_engine/config/environments/production.rb
|
89
89
|
- sample/login_engine/config/environments/development.rb
|
90
90
|
- sample/login_engine/config/environments/test.rb
|
91
|
-
- sample/depot/app/helpers/
|
92
|
-
- sample/depot/app/helpers/standard_form.rb
|
91
|
+
- sample/depot/app/helpers/cart_helper.rb
|
93
92
|
- sample/depot/app/helpers/application_helper.rb
|
94
93
|
- sample/depot/app/helpers/admin_helper.rb
|
94
|
+
- sample/depot/app/helpers/price_helper.rb
|
95
95
|
- sample/depot/app/helpers/store_helper.rb
|
96
|
-
- sample/depot/app/helpers/form_tag.rb
|
97
96
|
- sample/depot/app/helpers/info_helper.rb
|
98
97
|
- sample/depot/app/controllers/admin_controller.rb
|
99
98
|
- sample/depot/app/controllers/login_controller.rb
|
@@ -116,8 +115,6 @@ files:
|
|
116
115
|
- sample/depot/test/unit/order_test.rb
|
117
116
|
- sample/depot/test/unit/cart_test.rb
|
118
117
|
- sample/depot/test/unit/product_test.rb
|
119
|
-
- sample/depot/test/integration/user_stories_test.rb
|
120
|
-
- sample/depot/test/integration/dsl_user_stories_test.rb
|
121
118
|
- sample/depot/test/performance/order_speed_test.rb
|
122
119
|
- sample/depot/public/dispatch.rb
|
123
120
|
- sample/depot/db/schema.rb
|
@@ -129,13 +126,37 @@ files:
|
|
129
126
|
- sample/depot/db/migrate/006_create_line_items.rb
|
130
127
|
- sample/depot/db/migrate/003_add_test_data.rb
|
131
128
|
- sample/depot/vendor/plugins/amrita2/init.rb
|
129
|
+
- sample/depot/vendor/plugins/will_paginate/init.rb
|
130
|
+
- sample/depot/vendor/plugins/will_paginate/lib/will_paginate.rb
|
131
|
+
- sample/depot/vendor/plugins/will_paginate/lib/will_paginate/collection.rb
|
132
|
+
- sample/depot/vendor/plugins/will_paginate/lib/will_paginate/finder.rb
|
133
|
+
- sample/depot/vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb
|
134
|
+
- sample/depot/vendor/plugins/will_paginate/lib/will_paginate/view_helpers.rb
|
135
|
+
- sample/depot/vendor/plugins/will_paginate/test/helper.rb
|
136
|
+
- sample/depot/vendor/plugins/will_paginate/test/finder_test.rb
|
137
|
+
- sample/depot/vendor/plugins/will_paginate/test/array_pagination_test.rb
|
138
|
+
- sample/depot/vendor/plugins/will_paginate/test/pagination_test.rb
|
139
|
+
- sample/depot/vendor/plugins/will_paginate/test/boot.rb
|
140
|
+
- sample/depot/vendor/plugins/will_paginate/test/fixtures/project.rb
|
141
|
+
- sample/depot/vendor/plugins/will_paginate/test/fixtures/developer.rb
|
142
|
+
- sample/depot/vendor/plugins/will_paginate/test/fixtures/user.rb
|
143
|
+
- sample/depot/vendor/plugins/will_paginate/test/fixtures/company.rb
|
144
|
+
- sample/depot/vendor/plugins/will_paginate/test/fixtures/schema.rb
|
145
|
+
- sample/depot/vendor/plugins/will_paginate/test/fixtures/reply.rb
|
146
|
+
- sample/depot/vendor/plugins/will_paginate/test/fixtures/topic.rb
|
147
|
+
- sample/depot/vendor/plugins/will_paginate/test/fixtures/admin.rb
|
148
|
+
- sample/depot/vendor/plugins/will_paginate/test/lib/activerecord_test_connector.rb
|
149
|
+
- sample/depot/vendor/plugins/will_paginate/test/lib/activerecord_test_case.rb
|
150
|
+
- sample/depot/vendor/plugins/will_paginate/test/lib/load_fixtures.rb
|
132
151
|
- sample/depot/config/routes.rb
|
133
152
|
- sample/depot/config/environment.rb
|
134
153
|
- sample/depot/config/boot.rb
|
135
154
|
- sample/depot/config/environments/production.rb
|
136
155
|
- sample/depot/config/environments/development.rb
|
137
156
|
- sample/depot/config/environments/test.rb
|
157
|
+
- sample/hello/test1.rb
|
138
158
|
- sample/hello/hello.rb
|
159
|
+
- sample/ramaze/ramaise_amrita2.rb
|
139
160
|
- README
|
140
161
|
- init.rb
|
141
162
|
test_files: []
|
@@ -1,169 +0,0 @@
|
|
1
|
-
require 'amrita2/macro'
|
2
|
-
|
3
|
-
|
4
|
-
module Amrita2View
|
5
|
-
class InputField < Amrita2::Macro::Base
|
6
|
-
include Amrita2
|
7
|
-
include Amrita2::Util
|
8
|
-
|
9
|
-
attr_accessor :set_value
|
10
|
-
|
11
|
-
def get_macro_template
|
12
|
-
%[<input macro:filter="Attr" />]
|
13
|
-
end
|
14
|
-
|
15
|
-
def macro_data(element)
|
16
|
-
attrs = element.as_amrita_dictionary
|
17
|
-
prefix = attrs.delete(:prefix).to_s.split
|
18
|
-
input_id = attrs.delete(:id)
|
19
|
-
if attrs.delete(:set_value)
|
20
|
-
self.set_value = true
|
21
|
-
end
|
22
|
-
default_attrs.merge(attrs).merge( {
|
23
|
-
:id => get_id(prefix, input_id),
|
24
|
-
:name => get_name(prefix, input_id),
|
25
|
-
:target_filter => target_filter(input_id)
|
26
|
-
} )
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def target_filter(input_id)
|
32
|
-
if set_value
|
33
|
-
"Attr[:value=>#{input_id.intern.inspect}]"
|
34
|
-
else
|
35
|
-
nil
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def get_id(prefix, name)
|
40
|
-
(prefix + [name]).join("_")
|
41
|
-
end
|
42
|
-
|
43
|
-
def get_name(prefix, name)
|
44
|
-
case prefix.size
|
45
|
-
when 0
|
46
|
-
name
|
47
|
-
when 1
|
48
|
-
"#{prefix.first}[#{name}]"
|
49
|
-
else
|
50
|
-
prefix.first +
|
51
|
-
prefix[1..-1].collect do |pre|
|
52
|
-
"[#{pre}]"
|
53
|
-
end.join('') +
|
54
|
-
"[#{name}]"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
class TextField < InputField
|
60
|
-
|
61
|
-
Option = {
|
62
|
-
:tag => "ar:text_field",
|
63
|
-
}
|
64
|
-
|
65
|
-
def default_attrs
|
66
|
-
{
|
67
|
-
:type => 'text',
|
68
|
-
:size => 30
|
69
|
-
}
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
class TextArea < InputField
|
74
|
-
|
75
|
-
Option = {
|
76
|
-
:tag => "ar:textarea",
|
77
|
-
}
|
78
|
-
|
79
|
-
def get_macro_template
|
80
|
-
%[<textarea macro:filter="Attr" />]
|
81
|
-
end
|
82
|
-
|
83
|
-
def default_attrs
|
84
|
-
{
|
85
|
-
:rows => 20,
|
86
|
-
:cols => 40,
|
87
|
-
}
|
88
|
-
end
|
89
|
-
|
90
|
-
def target_filter(input_id)
|
91
|
-
if set_value
|
92
|
-
"Attr[:body=>#{input_id.intern.inspect}]"
|
93
|
-
else
|
94
|
-
nil
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
class ARForm < Amrita2::Macro::Base
|
100
|
-
include Amrita2
|
101
|
-
TemplateText = <<-'END'
|
102
|
-
<<:|Amrita2View::ARFormFilter[{:prefix => :uuuu}] <
|
103
|
-
<<:contents>>
|
104
|
-
END
|
105
|
-
|
106
|
-
Option = {
|
107
|
-
:tag=>"ar:form",
|
108
|
-
:use_contents=>:contents
|
109
|
-
}
|
110
|
-
|
111
|
-
FieldMacros = []
|
112
|
-
|
113
|
-
def self.add_macro(m)
|
114
|
-
FieldMacros << m
|
115
|
-
end
|
116
|
-
|
117
|
-
add_macro TextField
|
118
|
-
add_macro TextArea
|
119
|
-
|
120
|
-
def initialize
|
121
|
-
@filter = Amrita2::Filters::MacroFilter.new(*FieldMacros)
|
122
|
-
super
|
123
|
-
end
|
124
|
-
|
125
|
-
def process(de, element)
|
126
|
-
@filter.macros.each do |m|
|
127
|
-
m.set_value = element.get_attribute("set_value")
|
128
|
-
end
|
129
|
-
element = process_prefix(element, [])
|
130
|
-
@filter.filter_element(de, element).to_s
|
131
|
-
end
|
132
|
-
|
133
|
-
private
|
134
|
-
|
135
|
-
def process_prefix(e, prefix)
|
136
|
-
if e.name == "ar:form"
|
137
|
-
prefix = prefix + [e.get_attribute("prefix")]
|
138
|
-
e.name = "_"
|
139
|
-
e.delete_attribute("prefix")
|
140
|
-
e.delete_attribute("set_value")
|
141
|
-
elsif @filter.macros.any? { |m| m.get_element_name == e.name }
|
142
|
-
e.set_attribute("prefix", prefix.join(" ")) unless e.get_attribute("prefix")
|
143
|
-
end
|
144
|
-
e.children.each do |c|
|
145
|
-
process_prefix(c, prefix) if c.kind_of?(Hpricot::Elem)
|
146
|
-
end
|
147
|
-
e
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
class FormTag < Amrita2::Macro::Base
|
152
|
-
TemplateText = <<-END
|
153
|
-
<%
|
154
|
-
action = $_[:action]
|
155
|
-
method = $_[:method]
|
156
|
-
%>
|
157
|
-
<%%= form_tag({:action=><%= action.inspect%>}, {:method=><%= method.inspect %>}) %%>
|
158
|
-
<span macro:src='contents' />
|
159
|
-
<%%= "</form>" %%>
|
160
|
-
END
|
161
|
-
|
162
|
-
Option = {
|
163
|
-
:tag => :form_tag,
|
164
|
-
:use_contents => :contents
|
165
|
-
}
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
ARForm = Amrita2View::ARForm
|
@@ -1,24 +0,0 @@
|
|
1
|
-
|
2
|
-
class FormTag < Amrita2::Macro::Base
|
3
|
-
TemplateText = <<-END_OF_TEMPLATE
|
4
|
-
<%%= form_tag(<%= $_[:url].inspect %>) %%>
|
5
|
-
<<:contents>>
|
6
|
-
<%%= '</form>' %%>
|
7
|
-
|
8
|
-
END_OF_TEMPLATE
|
9
|
-
|
10
|
-
def macro_data(element)
|
11
|
-
root = element.as_amrita_dictionary
|
12
|
-
url = element.search("url").first
|
13
|
-
contents = element.children.find_all do |c|
|
14
|
-
c != url
|
15
|
-
end
|
16
|
-
|
17
|
-
ret = {
|
18
|
-
:url => url ? url.as_amrita_dictionary : {},
|
19
|
-
:contents => Amrita2::SanitizedString[contents]
|
20
|
-
}
|
21
|
-
ret
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
@@ -1,73 +0,0 @@
|
|
1
|
-
|
2
|
-
class StandardForm < Amrita2::Macro::Base
|
3
|
-
TemplateText = <<-END_OF_TEMPLATE
|
4
|
-
<<fieldset<
|
5
|
-
<<legend:title>>
|
6
|
-
<%%= form_tag(<%= $_[:url].inspect %>) %%>
|
7
|
-
<<:header>>
|
8
|
-
<<p:items<
|
9
|
-
<<label:label|Attr[:for]<
|
10
|
-
<<:text>>:
|
11
|
-
<<:input>>
|
12
|
-
<<:fotter>>
|
13
|
-
<%%= '</form>' %%>
|
14
|
-
|
15
|
-
END_OF_TEMPLATE
|
16
|
-
|
17
|
-
def macro_data(element)
|
18
|
-
root = element.as_amrita_dictionary
|
19
|
-
record = root[:record].intern
|
20
|
-
title = element.search("form_title").first
|
21
|
-
url = element.search("url").first
|
22
|
-
header = element.search("header").first
|
23
|
-
items = element.search("tr").collect do |tr|
|
24
|
-
tr_to_data(record, tr)
|
25
|
-
end
|
26
|
-
fotter = element.search("fotter").first
|
27
|
-
|
28
|
-
ret = {
|
29
|
-
:title => title.contents,
|
30
|
-
:record => record,
|
31
|
-
:url => url ? url.as_amrita_dictionary : {},
|
32
|
-
:header => header.contents,
|
33
|
-
:items => items,
|
34
|
-
:fotter => fotter.contents
|
35
|
-
}
|
36
|
-
ret
|
37
|
-
end
|
38
|
-
|
39
|
-
def tr_to_data(record, tr)
|
40
|
-
label = tr.search("th").first
|
41
|
-
td = tr.search("td").first
|
42
|
-
input = td_to_input(record, td) || { }
|
43
|
-
{
|
44
|
-
:label => {
|
45
|
-
:for => "#{record}_#{input[:field_id]}",
|
46
|
-
:text => label.contents.strip,
|
47
|
-
},
|
48
|
-
:input => input[:input]
|
49
|
-
}
|
50
|
-
end
|
51
|
-
|
52
|
-
def td_to_input(record, td)
|
53
|
-
x = td.children.find { |c| c.kind_of?(Hpricot::Elem) }
|
54
|
-
raise "input was not found in <td>" unless x
|
55
|
-
attr = x.as_amrita_dictionary
|
56
|
-
field_id = attr.delete(:id)
|
57
|
-
input = case x.name
|
58
|
-
when "text"
|
59
|
-
"<%= text_field #{record.to_s.inspect}, #{field_id.to_s.inspect}, #{attr.inspect} %>"
|
60
|
-
when "text_area"
|
61
|
-
"<%= text_area #{record.to_s.inspect}, #{field_id.to_s.inspect}, #{attr.inspect} %>"
|
62
|
-
when "field"
|
63
|
-
x.contents
|
64
|
-
else
|
65
|
-
raise "unknown input field #{x.name} "
|
66
|
-
end
|
67
|
-
{
|
68
|
-
:input => Amrita2::SanitizedString[input],
|
69
|
-
:field_id => field_id
|
70
|
-
}
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
@@ -1,126 +0,0 @@
|
|
1
|
-
#---
|
2
|
-
# Excerpted from "Agile Web Development with Rails, 2nd Ed."
|
3
|
-
# We make no guarantees that this code is fit for any purpose.
|
4
|
-
# Visit http://www.pragmaticprogrammer.com/titles/rails2 for more book information.
|
5
|
-
#---
|
6
|
-
require "#{File.dirname(__FILE__)}/../test_helper"
|
7
|
-
|
8
|
-
class DslUserStoriesTest < ActionController::IntegrationTest
|
9
|
-
fixtures :products
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
DAVES_DETAILS = {
|
14
|
-
:name => "Dave Thomas",
|
15
|
-
:address => "123 The Street",
|
16
|
-
:email => "dave@pragprog.com",
|
17
|
-
:pay_type => "check"
|
18
|
-
}
|
19
|
-
|
20
|
-
|
21
|
-
MIKES_DETAILS = {
|
22
|
-
:name => "Mike Clark",
|
23
|
-
:address => "345 The Avenue",
|
24
|
-
:email => "mike@pragmaticstudio.com",
|
25
|
-
:pay_type => "cc"
|
26
|
-
}
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
def setup
|
31
|
-
LineItem.delete_all
|
32
|
-
Order.delete_all
|
33
|
-
@ruby_book = products(:ruby_book)
|
34
|
-
@rails_book = products(:rails_book)
|
35
|
-
end
|
36
|
-
|
37
|
-
# A user goes to the store index page. They select a product,
|
38
|
-
# adding it to their cart. They then check out, filling in
|
39
|
-
# their details on the checkout form. When they submit,
|
40
|
-
# an order is created in the database containing
|
41
|
-
# their information, along with a single line item
|
42
|
-
# corresponding to the product they added to their cart.
|
43
|
-
|
44
|
-
|
45
|
-
def test_buying_a_product
|
46
|
-
dave = regular_user
|
47
|
-
dave.get "/store/index"
|
48
|
-
dave.is_viewing "index"
|
49
|
-
dave.buys_a @ruby_book
|
50
|
-
dave.has_a_cart_containing @ruby_book
|
51
|
-
dave.checks_out DAVES_DETAILS
|
52
|
-
dave.is_viewing "index"
|
53
|
-
check_for_order DAVES_DETAILS, @ruby_book
|
54
|
-
end
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
def test_two_people_buying
|
59
|
-
dave = regular_user
|
60
|
-
mike = regular_user
|
61
|
-
dave.buys_a @ruby_book
|
62
|
-
mike.buys_a @rails_book
|
63
|
-
dave.has_a_cart_containing @ruby_book
|
64
|
-
dave.checks_out DAVES_DETAILS
|
65
|
-
mike.has_a_cart_containing @rails_book
|
66
|
-
check_for_order DAVES_DETAILS, @ruby_book
|
67
|
-
mike.checks_out MIKES_DETAILS
|
68
|
-
check_for_order MIKES_DETAILS, @rails_book
|
69
|
-
end
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
def regular_user
|
74
|
-
open_session do |user|
|
75
|
-
def user.is_viewing(page)
|
76
|
-
assert_response :success
|
77
|
-
assert_template page
|
78
|
-
end
|
79
|
-
|
80
|
-
def user.buys_a(product)
|
81
|
-
xml_http_request "/store/add_to_cart", :id => product.id
|
82
|
-
assert_response :success
|
83
|
-
end
|
84
|
-
|
85
|
-
def user.has_a_cart_containing(*products)
|
86
|
-
cart = session[:cart]
|
87
|
-
assert_equal products.size, cart.items.size
|
88
|
-
for item in cart.items
|
89
|
-
assert products.include?(item.product)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def user.checks_out(details)
|
94
|
-
post "/store/checkout"
|
95
|
-
assert_response :success
|
96
|
-
assert_template "checkout"
|
97
|
-
|
98
|
-
post_via_redirect "/store/save_order",
|
99
|
-
:order => { :name => details[:name],
|
100
|
-
:address => details[:address],
|
101
|
-
:email => details[:email],
|
102
|
-
:pay_type => details[:pay_type]
|
103
|
-
}
|
104
|
-
assert_response :success
|
105
|
-
assert_template "index"
|
106
|
-
assert_equal 0, session[:cart].items.size
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
|
112
|
-
def check_for_order(details, *products)
|
113
|
-
order = Order.find_by_name(details[:name])
|
114
|
-
assert_not_nil order
|
115
|
-
|
116
|
-
assert_equal details[:name], order.name
|
117
|
-
assert_equal details[:address], order.address
|
118
|
-
assert_equal details[:email], order.email
|
119
|
-
assert_equal details[:pay_type], order.pay_type
|
120
|
-
|
121
|
-
assert_equal products.size, order.line_items.size
|
122
|
-
for line_item in order.line_items
|
123
|
-
assert products.include?(line_item.product)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|