resty-generators 0.7.2 → 0.7.3
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/features/generators.feature +10 -10
- data/lib/generators/resty/model/model_generator.rb +7 -1
- data/lib/generators/resty/scaffold/scaffold_generator.rb +1 -1
- data/lib/generators/resty/setup/setup_generator.rb +61 -46
- data/lib/generators/resty/setup/templates/ActivityPlaceActivityMapper.java +1 -1
- data/lib/generators/resty/setup/templates/Application.java +31 -0
- data/lib/generators/resty/setup/templates/Application.java~ +95 -0
- data/lib/generators/resty/setup/templates/ApplicationLinksPanel.java +29 -0
- data/lib/generators/resty/setup/templates/ApplicationLinksPanel.java~ +29 -0
- data/lib/generators/resty/setup/templates/BreadCrumbsPanel.java +2 -2
- data/lib/generators/resty/setup/templates/EntryPoint.java +14 -4
- data/lib/generators/resty/setup/templates/LoginActivity.java +2 -2
- data/lib/generators/resty/setup/templates/Mavenfile +10 -2
- data/lib/generators/resty/setup/templates/SessionActivityPlaceActivityMapper.java +3 -3
- data/lib/generators/resty/setup/templates/User.java +14 -1
- data/lib/generators/resty/setup/templates/application.rb +15 -0
- data/lib/generators/resty/setup/templates/authentication.rb +2 -2
- data/lib/generators/resty/setup/templates/gwt.css +13 -1
- data/lib/generators/resty/setup/templates/remote_user.rb +1 -1
- data/lib/generators/resty/setup/templates/remote_user.rb~ +1 -1
- data/lib/generators/resty/setup/templates/session.rb +7 -0
- data/lib/generators/resty/setup/templates/sessions_controller.rb +2 -2
- data/lib/generators/resty/setup/templates/user.rb +23 -5
- data/lib/generators/resty/templates/Activity.java +22 -5
- data/lib/generators/resty/templates/Editor.java +1 -0
- data/lib/generators/resty/templates/Model.java +8 -2
- data/lib/generators/resty/templates/RestService.java +0 -1
- data/lib/ixtlan/core/heartbeat.rb~ +8 -2
- data/lib/rails_gwt/dsl.rb +210 -0
- data/lib/rails_gwt/dsl.rb~ +210 -0
- data/lib/rails_gwt/user_config.rb +80 -0
- data/lib/rails_gwt/user_config.rb~ +76 -0
- metadata +11 -3
- data/lib/ixtlan/core/heartbeat.rb +0 -59
@@ -0,0 +1,210 @@
|
|
1
|
+
require 'rails_gwt/user_config'
|
2
|
+
|
3
|
+
Capybara.default_driver = :selenium
|
4
|
+
Capybara.automatic_reload = false
|
5
|
+
Capybara.default_wait_time = 10
|
6
|
+
#Capybara.register_driver :selenium do |app|
|
7
|
+
# Capybara::Selenium::Driver.new(app, :resynchronize => true)
|
8
|
+
#end
|
9
|
+
|
10
|
+
#sqlite3 can have only one connection at the time
|
11
|
+
class ActiveRecord::Base
|
12
|
+
mattr_accessor :shared_connection
|
13
|
+
@@shared_connection = nil
|
14
|
+
|
15
|
+
def self.connection
|
16
|
+
@@shared_connection || retrieve_connection
|
17
|
+
end
|
18
|
+
end
|
19
|
+
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
|
20
|
+
|
21
|
+
module RailsGwt
|
22
|
+
module DSL
|
23
|
+
include Capybara::DSL
|
24
|
+
|
25
|
+
def login_session(username, use_last_pwd = false)
|
26
|
+
puts "login user: '#{username}'"
|
27
|
+
if use_last_pwd
|
28
|
+
line = File.read('log/test.log').gsub(/\r/, '').split("\n").grep(/new password :/).last
|
29
|
+
pwd = line.gsub(/.*new password : (.*)/ , '\1') if line
|
30
|
+
end
|
31
|
+
if pwd.blank?
|
32
|
+
fill_in 'username', :with => username
|
33
|
+
click_on('password reset')
|
34
|
+
page.should have_content('new password was sent to your email address')
|
35
|
+
|
36
|
+
pwd = File.read('log/test.log').gsub(/\r/, '').split("\n").grep(/new password :/).last.gsub(/.*new password : (.*)/ , '\1')
|
37
|
+
end
|
38
|
+
fill_in 'login', :with => username
|
39
|
+
fill_in 'password', :with => pwd
|
40
|
+
click_on('login')
|
41
|
+
|
42
|
+
should_have_no_loading
|
43
|
+
|
44
|
+
yield
|
45
|
+
|
46
|
+
click_on('logout')
|
47
|
+
page.should have_content('password reset')
|
48
|
+
end
|
49
|
+
|
50
|
+
def should_have_no_loading
|
51
|
+
page.should have_xpath('//div[@class = "gwt-rails-loading" and @style = "display: none;"]')
|
52
|
+
end
|
53
|
+
|
54
|
+
def dump_page
|
55
|
+
puts page.html.gsub(/></, ">\n<")
|
56
|
+
end
|
57
|
+
|
58
|
+
def should_have_button(name)
|
59
|
+
find(:xpath, "//button[text()='#{name}' and not(@style='display: none;')]")
|
60
|
+
end
|
61
|
+
|
62
|
+
def should_have_no_button(name)
|
63
|
+
find(:xpath, "//button[text()='#{name}' and @style='display: none;']")
|
64
|
+
end
|
65
|
+
|
66
|
+
def should_have_menu_items(*items)
|
67
|
+
found = []
|
68
|
+
all(:xpath, "//div[@class='gwt-rails-menu']/button").each do |b|
|
69
|
+
found << b.text if b[:style].blank?
|
70
|
+
end
|
71
|
+
found.sort!.should == items.flatten.sort
|
72
|
+
end
|
73
|
+
|
74
|
+
def should_have_no_model_display
|
75
|
+
find(:xpath, "//div[@class='gwt-rails-model' and @style='display: none;']")
|
76
|
+
end
|
77
|
+
|
78
|
+
def should_have_model_list_display
|
79
|
+
find(:xpath, "//div[@class='gwt-rails-model-list' and not(table/@style='display: none;')]")
|
80
|
+
end
|
81
|
+
|
82
|
+
def should_have_model_display
|
83
|
+
find(:xpath, "//div[@class='gwt-rails-model' and not(@style='display: none;')]")
|
84
|
+
end
|
85
|
+
|
86
|
+
def should_have_no_model_list_display
|
87
|
+
find(:xpath, "//div[@class='gwt-rails-model-list' and table/@style='display: none;']")
|
88
|
+
end
|
89
|
+
|
90
|
+
def should_have_action_button(name)
|
91
|
+
find(:xpath, "//div[@class='gwt-rails-model']//div[@class='gwt-rails-buttons']/button[text()='#{name}' and not(@style='display: none;')]")
|
92
|
+
end
|
93
|
+
|
94
|
+
def should_have_no_action_button(name)
|
95
|
+
find(:xpath, "//div[@class='gwt-rails-buttons']/button[text()='#{name}' and @style='display: none;']")
|
96
|
+
end
|
97
|
+
|
98
|
+
def within_page(path, mode = :page, &block)
|
99
|
+
puts "visit page: #{path}"
|
100
|
+
visit "#{path}"
|
101
|
+
should_have_no_loading
|
102
|
+
|
103
|
+
case mode
|
104
|
+
when :index
|
105
|
+
should_have_no_model_display
|
106
|
+
should_have_model_list_display
|
107
|
+
when :page
|
108
|
+
should_have_model_display
|
109
|
+
should_have_no_model_list_display
|
110
|
+
when :singleton
|
111
|
+
should_have_model_display
|
112
|
+
end
|
113
|
+
|
114
|
+
block.call if block
|
115
|
+
end
|
116
|
+
|
117
|
+
def should_have_no_action_buttons
|
118
|
+
should_have_action_buttons
|
119
|
+
end
|
120
|
+
|
121
|
+
def should_have_action_buttons(*buttons)
|
122
|
+
buttons = buttons.flatten
|
123
|
+
found = []
|
124
|
+
all(:xpath, "//div[@class='gwt-rails-model']//div[@class='gwt-rails-buttons']/button").each do |b|
|
125
|
+
found << b.text unless b.text.blank?
|
126
|
+
end
|
127
|
+
(found || bottons).each do |button|
|
128
|
+
if buttons.member? button
|
129
|
+
should_have_action_button(button) unless button.blank?
|
130
|
+
else
|
131
|
+
should_have_no_action_button(button) unless button.blank?
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def should_have_no_buttons
|
137
|
+
should_have_buttons
|
138
|
+
end
|
139
|
+
|
140
|
+
def should_have_buttons(*buttons)
|
141
|
+
buttons = buttons.flatten
|
142
|
+
found = []
|
143
|
+
all(:xpath, "//div[contains(@class, 'gwt-rails-display')]/div[@class='gwt-rails-buttons']/button").each do |b|
|
144
|
+
text = b.text
|
145
|
+
found << text unless text.blank?
|
146
|
+
end
|
147
|
+
(found || buttons).each do |button|
|
148
|
+
if buttons.member? button
|
149
|
+
should_have_button(button)
|
150
|
+
else
|
151
|
+
should_have_no_button(button)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def visit_resource(config, &block)
|
157
|
+
puts "----- resource: '#{config.resource}'"
|
158
|
+
page.should have_content("Welcome #{config.name}")
|
159
|
+
page.should have_content('logout')
|
160
|
+
|
161
|
+
should_have_menu_items(config.menu)
|
162
|
+
|
163
|
+
config.action = :new
|
164
|
+
if config.action
|
165
|
+
within_page("/Users.html##{config.resource}/new", config.mode) do
|
166
|
+
should_have_action_buttons(config.action_buttons)
|
167
|
+
should_have_buttons(config.buttons)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
config.action = :edit
|
172
|
+
if config.action
|
173
|
+
id = config.mode == :singleton ? '' : "/#{config.resource_id}"
|
174
|
+
within_page("/Users.html##{config.resource}#{id}/edit", config.mode) do
|
175
|
+
should_have_action_buttons(config.action_buttons)
|
176
|
+
should_have_buttons(config.buttons)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
config.action = :show
|
181
|
+
if config.action
|
182
|
+
id = config.mode == :singleton ? '' : "/#{config.resource_id}"
|
183
|
+
within_page("/Users.html##{config.resource}#{id}", config.mode) do
|
184
|
+
should_have_action_buttons(config.action_buttons)
|
185
|
+
should_have_buttons(config.buttons)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
config.action = :index
|
190
|
+
if config.action
|
191
|
+
within_page("/Users.html##{config.resource}", :index) do
|
192
|
+
should_have_action_buttons(config.action_buttons)
|
193
|
+
should_have_buttons(config.buttons)
|
194
|
+
end
|
195
|
+
|
196
|
+
# list
|
197
|
+
config.content.each do |item|
|
198
|
+
page.should have_content(item)
|
199
|
+
end
|
200
|
+
|
201
|
+
# no user list after search
|
202
|
+
# fill_in 'search', :with => 'pipapo'
|
203
|
+
# page.should have_no_content('root@example.com')
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
block.call(config) if block
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
@@ -0,0 +1,210 @@
|
|
1
|
+
requrie File.join(File.dirname(__FILE__), 'user_config.rb')
|
2
|
+
|
3
|
+
Capybara.default_driver = :selenium
|
4
|
+
Capybara.automatic_reload = false
|
5
|
+
Capybara.default_wait_time = 10
|
6
|
+
#Capybara.register_driver :selenium do |app|
|
7
|
+
# Capybara::Selenium::Driver.new(app, :resynchronize => true)
|
8
|
+
#end
|
9
|
+
|
10
|
+
#sqlite3 can have only one connection at the time
|
11
|
+
class ActiveRecord::Base
|
12
|
+
mattr_accessor :shared_connection
|
13
|
+
@@shared_connection = nil
|
14
|
+
|
15
|
+
def self.connection
|
16
|
+
@@shared_connection || retrieve_connection
|
17
|
+
end
|
18
|
+
end
|
19
|
+
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
|
20
|
+
|
21
|
+
module RailsGwt
|
22
|
+
module DSL
|
23
|
+
include Capybara::DSL
|
24
|
+
|
25
|
+
def login_session(username, use_last_pwd = false)
|
26
|
+
puts "login user: '#{username}'"
|
27
|
+
if use_last_pwd
|
28
|
+
line = File.read('log/test.log').gsub(/\r/, '').split("\n").grep(/new password :/).last
|
29
|
+
pwd = line.gsub(/.*new password : (.*)/ , '\1') if line
|
30
|
+
end
|
31
|
+
if pwd.blank?
|
32
|
+
fill_in 'username', :with => username
|
33
|
+
click_on('password reset')
|
34
|
+
page.should have_content('new password was sent to your email address')
|
35
|
+
|
36
|
+
pwd = File.read('log/test.log').gsub(/\r/, '').split("\n").grep(/new password :/).last.gsub(/.*new password : (.*)/ , '\1')
|
37
|
+
end
|
38
|
+
fill_in 'login', :with => username
|
39
|
+
fill_in 'password', :with => pwd
|
40
|
+
click_on('login')
|
41
|
+
|
42
|
+
should_have_no_loading
|
43
|
+
|
44
|
+
yield
|
45
|
+
|
46
|
+
click_on('logout')
|
47
|
+
page.should have_content('password reset')
|
48
|
+
end
|
49
|
+
|
50
|
+
def should_have_no_loading
|
51
|
+
page.should have_xpath('//div[@class = "gwt-rails-loading" and @style = "display: none;"]')
|
52
|
+
end
|
53
|
+
|
54
|
+
def dump_page
|
55
|
+
puts page.html.gsub(/></, ">\n<")
|
56
|
+
end
|
57
|
+
|
58
|
+
def should_have_button(name)
|
59
|
+
find(:xpath, "//button[text()='#{name}' and not(@style='display: none;')]")
|
60
|
+
end
|
61
|
+
|
62
|
+
def should_have_no_button(name)
|
63
|
+
find(:xpath, "//button[text()='#{name}' and @style='display: none;']")
|
64
|
+
end
|
65
|
+
|
66
|
+
def should_have_menu_items(*items)
|
67
|
+
found = []
|
68
|
+
all(:xpath, "//div[@class='gwt-rails-menu']/button").each do |b|
|
69
|
+
found << b.text if b[:style].blank?
|
70
|
+
end
|
71
|
+
found.sort!.should == items.flatten.sort
|
72
|
+
end
|
73
|
+
|
74
|
+
def should_have_no_model_display
|
75
|
+
find(:xpath, "//div[@class='gwt-rails-model' and @style='display: none;']")
|
76
|
+
end
|
77
|
+
|
78
|
+
def should_have_model_list_display
|
79
|
+
find(:xpath, "//div[@class='gwt-rails-model-list' and not(table/@style='display: none;')]")
|
80
|
+
end
|
81
|
+
|
82
|
+
def should_have_model_display
|
83
|
+
find(:xpath, "//div[@class='gwt-rails-model' and not(@style='display: none;')]")
|
84
|
+
end
|
85
|
+
|
86
|
+
def should_have_no_model_list_display
|
87
|
+
find(:xpath, "//div[@class='gwt-rails-model-list' and table/@style='display: none;']")
|
88
|
+
end
|
89
|
+
|
90
|
+
def should_have_action_button(name)
|
91
|
+
find(:xpath, "//div[@class='gwt-rails-model']//div[@class='gwt-rails-buttons']/button[text()='#{name}' and not(@style='display: none;')]")
|
92
|
+
end
|
93
|
+
|
94
|
+
def should_have_no_action_button(name)
|
95
|
+
find(:xpath, "//div[@class='gwt-rails-buttons']/button[text()='#{name}' and @style='display: none;']")
|
96
|
+
end
|
97
|
+
|
98
|
+
def within_page(path, mode = :page, &block)
|
99
|
+
puts "visit page: #{path}"
|
100
|
+
visit "#{path}"
|
101
|
+
should_have_no_loading
|
102
|
+
|
103
|
+
case mode
|
104
|
+
when :index
|
105
|
+
should_have_no_model_display
|
106
|
+
should_have_model_list_display
|
107
|
+
when :page
|
108
|
+
should_have_model_display
|
109
|
+
should_have_no_model_list_display
|
110
|
+
when :singleton
|
111
|
+
should_have_model_display
|
112
|
+
end
|
113
|
+
|
114
|
+
block.call if block
|
115
|
+
end
|
116
|
+
|
117
|
+
def should_have_no_action_buttons
|
118
|
+
should_have_action_buttons
|
119
|
+
end
|
120
|
+
|
121
|
+
def should_have_action_buttons(*buttons)
|
122
|
+
buttons = buttons.flatten
|
123
|
+
found = []
|
124
|
+
all(:xpath, "//div[@class='gwt-rails-model']//div[@class='gwt-rails-buttons']/button").each do |b|
|
125
|
+
found << b.text unless b.text.blank?
|
126
|
+
end
|
127
|
+
(found || bottons).each do |button|
|
128
|
+
if buttons.member? button
|
129
|
+
should_have_action_button(button) unless button.blank?
|
130
|
+
else
|
131
|
+
should_have_no_action_button(button) unless button.blank?
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def should_have_no_buttons
|
137
|
+
should_have_buttons
|
138
|
+
end
|
139
|
+
|
140
|
+
def should_have_buttons(*buttons)
|
141
|
+
buttons = buttons.flatten
|
142
|
+
found = []
|
143
|
+
all(:xpath, "//div[contains(@class, 'gwt-rails-display')]/div[@class='gwt-rails-buttons']/button").each do |b|
|
144
|
+
text = b.text
|
145
|
+
found << text unless text.blank?
|
146
|
+
end
|
147
|
+
(found || buttons).each do |button|
|
148
|
+
if buttons.member? button
|
149
|
+
should_have_button(button)
|
150
|
+
else
|
151
|
+
should_have_no_button(button)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def visit_resource(config, &block)
|
157
|
+
puts "----- resource: '#{config.resource}'"
|
158
|
+
page.should have_content("Welcome #{config.name}")
|
159
|
+
page.should have_content('logout')
|
160
|
+
|
161
|
+
should_have_menu_items(config.menu)
|
162
|
+
|
163
|
+
config.action = :new
|
164
|
+
if config.action
|
165
|
+
within_page("/Users.html##{config.resource}/new", config.mode) do
|
166
|
+
should_have_action_buttons(config.action_buttons)
|
167
|
+
should_have_buttons(config.buttons)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
config.action = :edit
|
172
|
+
if config.action
|
173
|
+
id = config.mode == :singleton ? '' : "/#{config.resource_id}"
|
174
|
+
within_page("/Users.html##{config.resource}#{id}/edit", config.mode) do
|
175
|
+
should_have_action_buttons(config.action_buttons)
|
176
|
+
should_have_buttons(config.buttons)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
config.action = :show
|
181
|
+
if config.action
|
182
|
+
id = config.mode == :singleton ? '' : "/#{config.resource_id}"
|
183
|
+
within_page("/Users.html##{config.resource}#{id}", config.mode) do
|
184
|
+
should_have_action_buttons(config.action_buttons)
|
185
|
+
should_have_buttons(config.buttons)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
config.action = :index
|
190
|
+
if config.action
|
191
|
+
within_page("/Users.html##{config.resource}", :index) do
|
192
|
+
should_have_action_buttons(config.action_buttons)
|
193
|
+
should_have_buttons(config.buttons)
|
194
|
+
end
|
195
|
+
|
196
|
+
# list
|
197
|
+
config.content.each do |item|
|
198
|
+
page.should have_content(item)
|
199
|
+
end
|
200
|
+
|
201
|
+
# no user list after search
|
202
|
+
# fill_in 'search', :with => 'pipapo'
|
203
|
+
# page.should have_no_content('root@example.com')
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
block.call(config) if block
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module RailsGwt
|
2
|
+
class UserConfigFactory
|
3
|
+
|
4
|
+
def [](login)
|
5
|
+
UserConfig.new(login.to_sym, config[login.to_sym])
|
6
|
+
end
|
7
|
+
|
8
|
+
def add(login, user_config)
|
9
|
+
config[login.to_sym] = user_config
|
10
|
+
end
|
11
|
+
|
12
|
+
def logins
|
13
|
+
config.keys
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def config
|
19
|
+
@config ||= {}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class UserConfig
|
24
|
+
|
25
|
+
attr_reader :login, :name, :menu, :resource, :action
|
26
|
+
|
27
|
+
def initialize(login, config)
|
28
|
+
@user_config = config
|
29
|
+
raise "unknown login #{login}" unless @user_config
|
30
|
+
@login = login.to_s
|
31
|
+
@name = @user_config[:name]
|
32
|
+
@menu = @user_config[:menu]
|
33
|
+
end
|
34
|
+
|
35
|
+
def resources
|
36
|
+
@user_config.collect { |k,v| k.to_s if v.is_a? Hash }.delete_if { |i| i.nil? }.sort!.collect { |i| i.to_sym }
|
37
|
+
end
|
38
|
+
|
39
|
+
def resource=(resource)
|
40
|
+
@resource = resource.to_s.pluralize
|
41
|
+
@config = @user_config[resource]
|
42
|
+
end
|
43
|
+
|
44
|
+
def content
|
45
|
+
c = @config[@action][:content] || []
|
46
|
+
c = [c] unless c.is_a? Array
|
47
|
+
c
|
48
|
+
end
|
49
|
+
|
50
|
+
def buttons
|
51
|
+
c = @config[@action][:buttons] || []
|
52
|
+
c = [c] unless c.is_a? Array
|
53
|
+
c
|
54
|
+
end
|
55
|
+
|
56
|
+
def action_buttons
|
57
|
+
c = @config[@action][:action_buttons] || []
|
58
|
+
c = [c] unless c.is_a? Array
|
59
|
+
c
|
60
|
+
end
|
61
|
+
|
62
|
+
def action=(action)
|
63
|
+
@action = @config[action] ? action : nil
|
64
|
+
@action
|
65
|
+
end
|
66
|
+
|
67
|
+
def mode
|
68
|
+
@config[:mode] || :page
|
69
|
+
end
|
70
|
+
|
71
|
+
def resource_id
|
72
|
+
if id = @config[:resource_id]
|
73
|
+
self.class_eval(id)
|
74
|
+
else
|
75
|
+
1
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|