whowish_word 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.loadpath +5 -0
- data/.project +17 -0
- data/Gemfile +3 -0
- data/HOW_TO_BUILD_WHOWISH_HOOK.md +10 -0
- data/ISSUE.md +93 -0
- data/README.md +72 -0
- data/config.ru +4 -0
- data/lib/legacy/whowish_word/config.rb +1 -0
- data/lib/legacy/whowish_word/init.rb +4 -0
- data/lib/legacy/whowish_word/lib/app/controllers/whowish_word_controller.rb +115 -0
- data/lib/legacy/whowish_word/lib/app/controllers/whowish_word_email_controller.rb +66 -0
- data/lib/legacy/whowish_word/lib/app/controllers/whowish_word_facebook_controller.rb +62 -0
- data/lib/legacy/whowish_word/lib/app/models/mongodb/whowish_word.rb +12 -0
- data/lib/legacy/whowish_word/lib/app/models/mongodb/whowish_word_email.rb +10 -0
- data/lib/legacy/whowish_word/lib/app/models/mongodb/whowish_word_facebook.rb +28 -0
- data/lib/legacy/whowish_word/lib/app/models/mysql/whowish_word.rb +5 -0
- data/lib/legacy/whowish_word/lib/app/models/mysql/whowish_word_email.rb +5 -0
- data/lib/legacy/whowish_word/lib/app/models/mysql/whowish_word_facebook.rb +18 -0
- data/lib/legacy/whowish_word/lib/app/views/layouts/whowish_word_blank.html.erb +94 -0
- data/lib/legacy/whowish_word/lib/app/views/whowish_word/_javascript.html.erb +82 -0
- data/lib/legacy/whowish_word/lib/app/views/whowish_word/_row.html.erb +50 -0
- data/lib/legacy/whowish_word/lib/app/views/whowish_word/index.html.erb +219 -0
- data/lib/legacy/whowish_word/lib/app/views/whowish_word/login.html.erb +5 -0
- data/lib/legacy/whowish_word/lib/app/views/whowish_word_email/_row.html.erb +42 -0
- data/lib/legacy/whowish_word/lib/app/views/whowish_word_email/index.html.erb +99 -0
- data/lib/legacy/whowish_word/lib/app/views/whowish_word_facebook/_row.html.erb +48 -0
- data/lib/legacy/whowish_word/lib/app/views/whowish_word_facebook/index.html.erb +100 -0
- data/lib/legacy/whowish_word/lib/db_migration.rb +2 -0
- data/lib/legacy/whowish_word/lib/db_migration/mongodb.rb +0 -0
- data/lib/legacy/whowish_word/lib/db_migration/mysql.rb +60 -0
- data/lib/legacy/whowish_word/lib/hook.rb +186 -0
- data/lib/whowish_word.rb +1 -0
- data/lib/whowish_word/action_controller/base.rb +35 -0
- data/lib/whowish_word/action_mailer/base.rb +12 -0
- data/lib/whowish_word/action_view/base.rb +65 -0
- data/lib/whowish_word/action_view/template.rb +22 -0
- data/lib/whowish_word/authentication.rb +14 -0
- data/lib/whowish_word/constant.rb +9 -0
- data/lib/whowish_word/db_migration/active_record/whowish_word_html.rb +15 -0
- data/lib/whowish_word/initializer.rb +55 -0
- data/lib/whowish_word/rails/app/controllers/whowish_word_controller.rb +71 -0
- data/lib/whowish_word/rails/app/models/active_record/whowish_word_html.rb +4 -0
- data/lib/whowish_word/rails/app/models/mongoid/whowish_word_html.rb +10 -0
- data/lib/whowish_word/rails/public/javascripts/0_class.js +64 -0
- data/lib/whowish_word/rails/public/javascripts/0_jquery-1.6.4-whowish_word.js +9046 -0
- data/lib/whowish_word/rails/public/javascripts/1_csrf_and_authenticity_token_hook.js +9 -0
- data/lib/whowish_word/rails/public/javascripts/1_jquery.escape.js +23 -0
- data/lib/whowish_word/rails/public/javascripts/1_jquery.loading_button.js +66 -0
- data/lib/whowish_word/rails/public/javascripts/1_jquery.sizes.min.js +8 -0
- data/lib/whowish_word/rails/public/javascripts/2_whowish_word_variables.js +64 -0
- data/lib/whowish_word/rails/public/javascripts/3_whowish_word_dialog.js +136 -0
- data/lib/whowish_word/rails/public/javascripts/3_whowish_word_helper.js +94 -0
- data/lib/whowish_word/rails/public/javascripts/4_whowish_word.js +43 -0
- data/lib/whowish_word/rails/public/javascripts/4_whowish_word_content_handler.js +15 -0
- data/lib/whowish_word/rails/public/javascripts/4_whowish_word_creator.js +62 -0
- data/lib/whowish_word/rails/public/javascripts/5_whowish_word_common_creator.js +49 -0
- data/lib/whowish_word/rails/public/javascripts/6_whowish_word_element_creator.js +72 -0
- data/lib/whowish_word/rails/public/javascripts/6_whowish_word_html_creator.js +19 -0
- data/lib/whowish_word/rails/public/javascripts/6_whowish_word_select_creator.js +11 -0
- data/lib/whowish_word/rails/public/javascripts/6_whowish_word_text_creator.js +20 -0
- data/lib/whowish_word/rails/public/javascripts/6_whowish_word_value_creator.js +20 -0
- data/lib/whowish_word/rails/public/javascripts/7_whowish_word_attribute_handler.js +17 -0
- data/lib/whowish_word/rails/public/javascripts/7_whowish_word_html_handler.js +15 -0
- data/lib/whowish_word/rails/public/javascripts/7_whowish_word_text_handler.js +15 -0
- data/lib/whowish_word/rails/public/javascripts/7_whowish_word_value_handler.js +19 -0
- data/lib/whowish_word/rails/public/stylesheets/whowish_word.css +197 -0
- data/lib/whowish_word/whowish_word.rb +39 -0
- data/lib/whowish_word/word_for.rb +97 -0
- data/rails/Gemfile +18 -0
- data/rails/Gemfile.lock +130 -0
- data/rails/Rakefile +7 -0
- data/rails/app/assets/javascripts/integration.js +2 -0
- data/rails/app/assets/javascripts/test_javascript.js +2 -0
- data/rails/app/assets/javascripts/test_word_for.js +2 -0
- data/rails/app/assets/stylesheets/integration.css +4 -0
- data/rails/app/assets/stylesheets/test_javascript.css +4 -0
- data/rails/app/assets/stylesheets/test_word_for.css +4 -0
- data/rails/app/controllers/application_controller.rb +14 -0
- data/rails/app/controllers/home_controller.rb +9 -0
- data/rails/app/controllers/integration_controller.rb +5 -0
- data/rails/app/controllers/test_javascript_controller.rb +11 -0
- data/rails/app/controllers/test_word_for_controller.rb +5 -0
- data/rails/app/helpers/integration_helper.rb +2 -0
- data/rails/app/helpers/test_javascript_helper.rb +2 -0
- data/rails/app/helpers/test_word_for_helper.rb +2 -0
- data/rails/app/views/home/index.html.erb +95 -0
- data/rails/app/views/home/static_edit.html.erb +50 -0
- data/rails/app/views/home/static_edit_select.html.erb +9 -0
- data/rails/app/views/integration/attr.html.erb +1 -0
- data/rails/app/views/integration/index.html.erb +1 -0
- data/rails/app/views/integration/select.html.erb +3 -0
- data/rails/app/views/integration/value.html.erb +1 -0
- data/rails/app/views/layouts/integration.html.erb +14 -0
- data/rails/app/views/layouts/main.html.erb +14 -0
- data/rails/app/views/layouts/nested_test_word_for.html.erb +14 -0
- data/rails/app/views/layouts/test_javascript.html.erb +13 -0
- data/rails/app/views/layouts/test_word_for.html.erb +22 -0
- data/rails/app/views/test_javascript/change_value.html.erb +32 -0
- data/rails/app/views/test_javascript/index.html.erb +78 -0
- data/rails/app/views/test_word_for/_partial.html.erb +5 -0
- data/rails/app/views/test_word_for/index.html.erb +7 -0
- data/rails/config.ru +4 -0
- data/rails/config/application.rb +30 -0
- data/rails/config/boot.rb +9 -0
- data/rails/config/database.yml +25 -0
- data/rails/config/environment.rb +16 -0
- data/rails/config/initializers/whowish_word.rb +5 -0
- data/rails/config/mongoid.rb +6 -0
- data/rails/config/mongoid.yml +14 -0
- data/rails/config/routes.rb +7 -0
- data/rails/log/.gitignore +2 -0
- data/rails/mongo.bat +5 -0
- data/rails/public/jasmine/MIT.LICENSE +20 -0
- data/rails/public/jasmine/jasmine-html.js +190 -0
- data/rails/public/jasmine/jasmine.css +166 -0
- data/rails/public/jasmine/jasmine.js +2476 -0
- data/rails/public/jasmine/jasmine_favicon.png +0 -0
- data/rails/public/javascripts/jquery-1.6.4.js +9046 -0
- data/rails/public/sinonjs/sinonjs.js +2821 -0
- data/rails/public/stylesheets/main.css +22 -0
- data/rails/public/test/jquery_version.html +26 -0
- data/rails/script/rails +6 -0
- data/rails/spec/controllers/whowish_word_controller_spec.rb +56 -0
- data/rails/spec/integration/whowish_word_generator_spec.rb +116 -0
- data/rails/spec/integration/whowish_word_spec.rb +110 -0
- data/rails/spec/spec_helper.rb +44 -0
- data/rails/spec/support/browser.rb +194 -0
- data/rails/spec/support/json_rspec_helper.rb +9 -0
- data/rails/spec/support/mongoid_helper.rb +10 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/unit/word_for_attr_in_edit_mode_spec.rb +44 -0
- data/spec/unit/word_for_attr_spec.rb +44 -0
- data/spec/unit/word_for_in_edit_mode_spec.rb +44 -0
- data/spec/unit/word_for_spec.rb +44 -0
- data/whowish_word.gemspec +21 -0
- metadata +181 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
body, input, textarea, button, select, option, div, span {
|
2
|
+
font-family: 'Bitstream Vera Sans Mono','Courier',monospace;
|
3
|
+
margin: 0px 0px 0px 0px;
|
4
|
+
padding: 0px 0px 0px 0px;
|
5
|
+
line-height: 30px;
|
6
|
+
}
|
7
|
+
|
8
|
+
body > form > div {
|
9
|
+
display:block;
|
10
|
+
margin-left:25px;
|
11
|
+
margin-top:25px;
|
12
|
+
}
|
13
|
+
|
14
|
+
body > form > div > span {
|
15
|
+
display:block;
|
16
|
+
margin-top:5px;
|
17
|
+
}
|
18
|
+
|
19
|
+
body > form > div > span > b {
|
20
|
+
display:inline-block;
|
21
|
+
vertical-align: top;
|
22
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
5
|
+
<title>Untitled Document</title>
|
6
|
+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
|
7
|
+
<script type="text/javascript">
|
8
|
+
console.log("1.6.4 = " + $().jquery);
|
9
|
+
</script>
|
10
|
+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js" type="text/javascript"></script>
|
11
|
+
<script type="text/javascript">
|
12
|
+
console.log("1.6.3 = " + $().jquery);
|
13
|
+
var $$jj = $.noConflict();
|
14
|
+
|
15
|
+
console.log("1.6.4 = " + $().jquery);
|
16
|
+
console.log("1.6.3 = " + $$jj().jquery);
|
17
|
+
</script>
|
18
|
+
<script src="../javascripts/jquery-1.6.2.min.js" type="text/javascript"></script>
|
19
|
+
<script type="text/javascript">
|
20
|
+
console.log("1.6.4 = " + $().jquery);
|
21
|
+
console.log("1.6.2 = " + $j().jquery);
|
22
|
+
</script>
|
23
|
+
</head>
|
24
|
+
<body>
|
25
|
+
</body>
|
26
|
+
</html>
|
data/rails/script/rails
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby.exe
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WhowishWordController do
|
4
|
+
|
5
|
+
it "adds a word correctly" do
|
6
|
+
|
7
|
+
word_id = "some_controller/some_view.html.erb:some_word(en)"
|
8
|
+
content = "Hello"
|
9
|
+
|
10
|
+
post :change_word, {
|
11
|
+
:word_id => word_id,
|
12
|
+
:content => content
|
13
|
+
}
|
14
|
+
|
15
|
+
body = expect_json_response
|
16
|
+
body['ok'].should be_true
|
17
|
+
|
18
|
+
commit_database
|
19
|
+
|
20
|
+
word = WhowishWordHtml.first(:conditions=>{:word_id=>word_id})
|
21
|
+
word.content.should == content
|
22
|
+
|
23
|
+
WhowishWord.words[word_id].should == content
|
24
|
+
WhowishWord.words.length.should == 1
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
it "changes a word correctly" do
|
29
|
+
|
30
|
+
word_id = "some_controller/some_view.html.erb:some_word(en)"
|
31
|
+
content = "Hello"
|
32
|
+
|
33
|
+
WhowishWord.add_or_set_word(word_id, content)
|
34
|
+
WhowishWordHtml.create(:word_id=>word_id, :content=>content)
|
35
|
+
|
36
|
+
new_content = "Yo!"
|
37
|
+
|
38
|
+
post :change_word, {
|
39
|
+
:word_id => word_id,
|
40
|
+
:content => new_content
|
41
|
+
}
|
42
|
+
|
43
|
+
body = expect_json_response
|
44
|
+
body['ok'].should be_true
|
45
|
+
|
46
|
+
commit_database
|
47
|
+
|
48
|
+
word = WhowishWordHtml.first(:conditions=>{:word_id=>word_id})
|
49
|
+
word.content.should == new_content
|
50
|
+
|
51
|
+
WhowishWord.words[word_id].should == new_content
|
52
|
+
WhowishWord.words.length.should == 1
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require File.expand_path("../../../../lib/whowish_word",__FILE__)
|
3
|
+
|
4
|
+
module WhowishWordRspecHelper
|
5
|
+
|
6
|
+
include WhowishWord::Constant
|
7
|
+
|
8
|
+
def get_whowish_word(namespace, id, variables={})
|
9
|
+
|
10
|
+
var_keys= []
|
11
|
+
variables.each_pair { |key,value|
|
12
|
+
var_keys.push(key)
|
13
|
+
}
|
14
|
+
|
15
|
+
variables_clause = ""
|
16
|
+
variables_clause = "{#{var_keys.join(',')}}" if var_keys.length > 0
|
17
|
+
|
18
|
+
return "#{namespace}:#{id}(en)#{variables_clause}"
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_whowish_word_in_edit_mode(namespace, id, variables={})
|
23
|
+
|
24
|
+
return "<dfn>#{get_whowish_word_attr_in_edit_mode(namespace, id, variables)}</dfn>"
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_whowish_word_attr_in_edit_mode(namespace, id, variables={})
|
29
|
+
|
30
|
+
var_keys = []
|
31
|
+
variables.each_pair { |key,value|
|
32
|
+
var_keys.push(key)
|
33
|
+
}
|
34
|
+
|
35
|
+
variables_params = ""
|
36
|
+
variables_clause = ""
|
37
|
+
|
38
|
+
variables_params = "|#{var_keys.join(',')}" if var_keys.length > 0
|
39
|
+
variables_clause = "{#{var_keys.join(',')}}" if var_keys.length > 0
|
40
|
+
|
41
|
+
return PREFIX + \
|
42
|
+
SEPARATOR + \
|
43
|
+
"#{namespace}:#{id}(en)#{variables_params}" + \
|
44
|
+
SEPARATOR + \
|
45
|
+
"#{namespace}:#{id}(en)#{variables_clause}"
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'Generator spec' do
|
52
|
+
|
53
|
+
include WhowishWordRspecHelper
|
54
|
+
|
55
|
+
it "generates word_for correctly for all types of view (in edit mode)" do
|
56
|
+
|
57
|
+
goto '/test_word_for?edit_mode=yes'
|
58
|
+
|
59
|
+
html("view").should == get_whowish_word_in_edit_mode("test_word_for/index.html.erb", "text")
|
60
|
+
html("view_attr").should == get_whowish_word_attr_in_edit_mode("test_word_for/index.html.erb", "text")
|
61
|
+
|
62
|
+
html("view_with_variables").should == get_whowish_word_in_edit_mode("test_word_for/index.html.erb", "text", {:number=>5,:name=>"tanin"})
|
63
|
+
html("view_attr_with_variables").should == get_whowish_word_attr_in_edit_mode("test_word_for/index.html.erb", "text", {:number=>5,:name=>"tanin"})
|
64
|
+
|
65
|
+
html("partial").should == get_whowish_word_in_edit_mode("test_word_for/_partial.html.erb", "text")
|
66
|
+
html("partial_attr").should == get_whowish_word_attr_in_edit_mode("test_word_for/_partial.html.erb", "text")
|
67
|
+
|
68
|
+
html("partial_with_variables").should == get_whowish_word_in_edit_mode("test_word_for/_partial.html.erb", "text", {:number=>5,:name=>"tanin"})
|
69
|
+
html("partial_attr_with_variables").should == get_whowish_word_attr_in_edit_mode("test_word_for/_partial.html.erb", "text", {:number=>5,:name=>"tanin"})
|
70
|
+
|
71
|
+
html("nested_layout").should == get_whowish_word_in_edit_mode("layouts/nested_test_word_for.html.erb", "text")
|
72
|
+
html("nested_layout_attr").should == get_whowish_word_attr_in_edit_mode("layouts/nested_test_word_for.html.erb", "text")
|
73
|
+
|
74
|
+
html("nested_layout_with_variables").should == get_whowish_word_in_edit_mode("layouts/nested_test_word_for.html.erb", "text", {:number=>5,:name=>"tanin"})
|
75
|
+
html("nested_layout_attr_with_variables").should == get_whowish_word_attr_in_edit_mode("layouts/nested_test_word_for.html.erb", "text", {:number=>5,:name=>"tanin"})
|
76
|
+
|
77
|
+
html("layout").should == get_whowish_word_in_edit_mode("layouts/test_word_for.html.erb", "text")
|
78
|
+
html("layout_attr").should == get_whowish_word_attr_in_edit_mode("layouts/test_word_for.html.erb", "text")
|
79
|
+
|
80
|
+
html("layout_with_variables").should == get_whowish_word_in_edit_mode("layouts/test_word_for.html.erb", "text", {:number=>5,:name=>"tanin"})
|
81
|
+
html("layout_attr_with_variables").should == get_whowish_word_attr_in_edit_mode("layouts/test_word_for.html.erb", "text", {:number=>5,:name=>"tanin"})
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
it "generates word_for correctly for all types of view" do
|
86
|
+
|
87
|
+
goto '/test_word_for'
|
88
|
+
|
89
|
+
html("view").should == get_whowish_word("test_word_for/index.html.erb", "text")
|
90
|
+
html("view_attr").should == get_whowish_word("test_word_for/index.html.erb", "text")
|
91
|
+
|
92
|
+
html("view_with_variables").should == get_whowish_word("test_word_for/index.html.erb", "text", {:number=>5,:name=>"tanin"})
|
93
|
+
html("view_attr_with_variables").should == get_whowish_word("test_word_for/index.html.erb", "text", {:number=>5,:name=>"tanin"})
|
94
|
+
|
95
|
+
html("partial").should == get_whowish_word("test_word_for/_partial.html.erb", "text")
|
96
|
+
html("partial_attr").should == get_whowish_word("test_word_for/_partial.html.erb", "text")
|
97
|
+
|
98
|
+
html("partial_with_variables").should == get_whowish_word("test_word_for/_partial.html.erb", "text", {:number=>5,:name=>"tanin"})
|
99
|
+
html("partial_attr_with_variables").should == get_whowish_word("test_word_for/_partial.html.erb", "text", {:number=>5,:name=>"tanin"})
|
100
|
+
|
101
|
+
html("nested_layout").should == get_whowish_word("layouts/nested_test_word_for.html.erb", "text")
|
102
|
+
html("nested_layout_attr").should == get_whowish_word("layouts/nested_test_word_for.html.erb", "text")
|
103
|
+
|
104
|
+
html("nested_layout_with_variables").should == get_whowish_word("layouts/nested_test_word_for.html.erb", "text", {:number=>5,:name=>"tanin"})
|
105
|
+
html("nested_layout_attr_with_variables").should == get_whowish_word("layouts/nested_test_word_for.html.erb", "text", {:number=>5,:name=>"tanin"})
|
106
|
+
|
107
|
+
html("layout").should == get_whowish_word("layouts/test_word_for.html.erb", "text")
|
108
|
+
html("layout_attr").should == get_whowish_word("layouts/test_word_for.html.erb", "text")
|
109
|
+
|
110
|
+
html("layout_with_variables").should == get_whowish_word("layouts/test_word_for.html.erb", "text", {:number=>5,:name=>"tanin"})
|
111
|
+
html("layout_attr_with_variables").should == get_whowish_word("layouts/test_word_for.html.erb", "text", {:number=>5,:name=>"tanin"})
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'WhowishWord workflow spec' do
|
4
|
+
|
5
|
+
it "edits a normal text" do
|
6
|
+
|
7
|
+
goto '/integration?edit_mode=yes'
|
8
|
+
|
9
|
+
click 'whowishWordId0_____html'
|
10
|
+
|
11
|
+
fill "whowishWordDialogContent", "Some new word"
|
12
|
+
click "whowishWordDialogSaveButton"
|
13
|
+
|
14
|
+
html('whowishWordId0').should == "Some new word"
|
15
|
+
|
16
|
+
commit_database
|
17
|
+
|
18
|
+
goto '/integration?edit_mode=yes'
|
19
|
+
|
20
|
+
html('whowishWordId0').should == "Some new word"
|
21
|
+
|
22
|
+
click 'whowishWordId0_____html'
|
23
|
+
value("whowishWordDialogContent").should == "Some new word"
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
it "edits a value" do
|
28
|
+
|
29
|
+
goto '/integration/value?edit_mode=yes'
|
30
|
+
|
31
|
+
click 'whowishWordId0_____value'
|
32
|
+
|
33
|
+
fill "whowishWordDialogContent", "Some new word"
|
34
|
+
click "whowishWordDialogSaveButton"
|
35
|
+
|
36
|
+
value('whowishWordId0').should == "Some new word"
|
37
|
+
|
38
|
+
commit_database
|
39
|
+
|
40
|
+
goto '/integration/value?edit_mode=yes'
|
41
|
+
|
42
|
+
value('whowishWordId0').should == "Some new word"
|
43
|
+
|
44
|
+
click 'whowishWordId0_____value'
|
45
|
+
value("whowishWordDialogContent").should == "Some new word"
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
it "edits an attribute" do
|
50
|
+
|
51
|
+
goto '/integration/attr?edit_mode=yes'
|
52
|
+
|
53
|
+
click 'whowishWordId0_____title'
|
54
|
+
|
55
|
+
fill "whowishWordDialogContent", "Some new word"
|
56
|
+
click "whowishWordDialogSaveButton"
|
57
|
+
|
58
|
+
element(:id=>'whowishWordId0').attribute_value("title").should == "Some new word"
|
59
|
+
|
60
|
+
commit_database
|
61
|
+
|
62
|
+
goto '/integration/attr?edit_mode=yes'
|
63
|
+
|
64
|
+
element(:id=>'whowishWordId0').attribute_value("title").should == "Some new word"
|
65
|
+
|
66
|
+
click 'whowishWordId0_____title'
|
67
|
+
element(:id=>'whowishWordId0').attribute_value("title").should == "Some new word"
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
it "edits an option" do
|
72
|
+
|
73
|
+
goto '/integration/select?edit_mode=yes'
|
74
|
+
|
75
|
+
|
76
|
+
click 'whowishWordId0_____value'
|
77
|
+
|
78
|
+
fill "whowishWordDialogContent", "Some new value"
|
79
|
+
click "whowishWordDialogSaveButton"
|
80
|
+
|
81
|
+
value('whowishWordId0').should == "Some new value"
|
82
|
+
|
83
|
+
|
84
|
+
click 'whowishWordId0_____text'
|
85
|
+
|
86
|
+
fill "whowishWordDialogContent", "Some new text"
|
87
|
+
click "whowishWordDialogSaveButton"
|
88
|
+
|
89
|
+
execute_script('return $("#whowishWordId0").text();').should == "Some new text"
|
90
|
+
|
91
|
+
|
92
|
+
commit_database
|
93
|
+
|
94
|
+
goto '/integration/select?edit_mode=yes'
|
95
|
+
|
96
|
+
value('whowishWordId0').should == "Some new value"
|
97
|
+
|
98
|
+
click 'whowishWordId0_____value'
|
99
|
+
value("whowishWordDialogContent").should == "Some new value"
|
100
|
+
click 'whowishWordDialogCloseButton'
|
101
|
+
|
102
|
+
execute_script('return $("#whowishWordId0").text();').should == "Some new text"
|
103
|
+
|
104
|
+
click 'whowishWordId0_____text'
|
105
|
+
value("whowishWordDialogContent").should == "Some new text"
|
106
|
+
click 'whowishWordDialogCloseButton'
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
ENV["RAILS_ENV"] ||= 'test'
|
5
|
+
|
6
|
+
require File.expand_path("../../config/environment", __FILE__)
|
7
|
+
|
8
|
+
require 'rspec/rails'
|
9
|
+
|
10
|
+
require 'watir-webdriver-rails'
|
11
|
+
|
12
|
+
WatirWebdriverRails.host = "localhost"
|
13
|
+
WatirWebdriverRails.port = 57124
|
14
|
+
|
15
|
+
Dir[File.expand_path("../support/**/*.rb", __FILE__)].each {|f| require f}
|
16
|
+
|
17
|
+
|
18
|
+
RSpec.configure do |config|
|
19
|
+
|
20
|
+
config.include Browser
|
21
|
+
config.include MongoidHelper
|
22
|
+
config.include JsonRspecHelper
|
23
|
+
|
24
|
+
config.before(:suite) do
|
25
|
+
|
26
|
+
class WhowishWordController
|
27
|
+
def authenticate;end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
config.before(:each) do
|
33
|
+
|
34
|
+
WhowishWordHtml.delete_all
|
35
|
+
WhowishWord.words = {}
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
config.mock_with :rspec
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
|
@@ -0,0 +1,194 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'uri'
|
3
|
+
module Browser
|
4
|
+
|
5
|
+
def goto(url)
|
6
|
+
browser.goto(url)
|
7
|
+
browser.execute_script("window.alert = function(msg) { window.lastAlert = msg; }")
|
8
|
+
sleep(0.1)
|
9
|
+
end
|
10
|
+
|
11
|
+
def expect_alert(msg)
|
12
|
+
wait_until { browser.execute_script("return window.lastAlert") == msg }
|
13
|
+
end
|
14
|
+
|
15
|
+
def click(id)
|
16
|
+
click_object(element(:id=>id))
|
17
|
+
end
|
18
|
+
|
19
|
+
def element(*option)
|
20
|
+
browser.element(*option)
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def click_object(obj)
|
25
|
+
|
26
|
+
inner_click(obj)
|
27
|
+
|
28
|
+
browser.wait(120)
|
29
|
+
wait_for_ajax
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def inner_click(obj)
|
34
|
+
|
35
|
+
if obj.id != nil and obj.id != ""
|
36
|
+
position = browser.execute_script "return $('##{obj.id}').css('position');"
|
37
|
+
left = browser.execute_script "return $('##{obj.id}').css('left');"
|
38
|
+
top = browser.execute_script "return $('##{obj.id}').css('top');"
|
39
|
+
|
40
|
+
browser.execute_script "$('##{obj.id}').css({position:'fixed',left:'0px',top:'0px'});"
|
41
|
+
end
|
42
|
+
|
43
|
+
obj.focus
|
44
|
+
|
45
|
+
if ["a","button"].include?(obj.tag_name.downcase)
|
46
|
+
obj.send_keys "\n"
|
47
|
+
else
|
48
|
+
obj.click
|
49
|
+
end
|
50
|
+
|
51
|
+
begin
|
52
|
+
if obj.id != nil and obj.id != ""
|
53
|
+
browser.execute_script "$('##{obj.id}').css({position:'#{position}',left:'#{left}',top:'#{top}'});"
|
54
|
+
end
|
55
|
+
rescue
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
def fill(id,msg,blur=true)
|
61
|
+
|
62
|
+
elem = browser.element(:id=>id)
|
63
|
+
|
64
|
+
if elem.tag_name.downcase == "iframe"
|
65
|
+
elem.focus
|
66
|
+
execute_script("$('##{id}').contents().find('body').html('')")
|
67
|
+
elem.send_keys msg
|
68
|
+
else
|
69
|
+
browser.text_field(:id=>id).focus
|
70
|
+
browser.text_field(:id=>id).set msg
|
71
|
+
end
|
72
|
+
|
73
|
+
if blur
|
74
|
+
rand_id = "watir_#{rand(100000)}"
|
75
|
+
browser.execute_script("$('body').append('<input type=\"button\" id=\"#{rand_id}\" />');")
|
76
|
+
click rand_id
|
77
|
+
browser.execute_script("$('##{rand_id}').remove();")
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
def upload_file(id, file_field_id, file_path)
|
83
|
+
browser.element(:id=>id).fire_event("onmouseover")
|
84
|
+
fill(file_field_id, file_path.gsub("/","\\"))
|
85
|
+
wait_for_ajax
|
86
|
+
end
|
87
|
+
|
88
|
+
def value(id)
|
89
|
+
browser.element(:id=>id).value
|
90
|
+
end
|
91
|
+
|
92
|
+
def html(id)
|
93
|
+
browser.execute_script("return document.getElementById('#{id}').innerHTML")
|
94
|
+
end
|
95
|
+
|
96
|
+
def expect_html_to_include(id,content)
|
97
|
+
begin
|
98
|
+
wait_until {
|
99
|
+
b = browser.element(:id=>id)
|
100
|
+
b.exist? && b.html.include?(content)
|
101
|
+
}
|
102
|
+
rescue Watir::Wait::TimeoutError => e
|
103
|
+
raise Watir::Wait::TimeoutError, "Content is expected to include '#{content}', instead we got '#{html(id)}'"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
def current_path
|
109
|
+
URI.parse(browser.execute_script("return document.location.toString();")).path.chomp('/')
|
110
|
+
end
|
111
|
+
|
112
|
+
def current_host
|
113
|
+
URI.parse(browser.execute_script("return document.location.toString();")).host.chomp('/')
|
114
|
+
end
|
115
|
+
|
116
|
+
def close_window
|
117
|
+
execute_script('window.close();')
|
118
|
+
end
|
119
|
+
|
120
|
+
def use_window_if_visible(part_of_url_regexp,&block)
|
121
|
+
|
122
|
+
begin
|
123
|
+
use_window(part_of_url_regexp,&block)
|
124
|
+
rescue Watir::Exception::NoMatchingWindowFoundException => e
|
125
|
+
# ignore it
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
def use_window(part_of_url_regexp,&block)
|
131
|
+
|
132
|
+
timeout = 30
|
133
|
+
count = 0
|
134
|
+
while true
|
135
|
+
|
136
|
+
begin
|
137
|
+
browser.window(:url => part_of_url_regexp).use(&block)
|
138
|
+
break
|
139
|
+
rescue Watir::Exception::NoMatchingWindowFoundException => e
|
140
|
+
sleep(1)
|
141
|
+
count += 1
|
142
|
+
raise e if count > timeout
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
def wait_until_present(id)
|
150
|
+
browser.element(:id=>id).wait_until_present
|
151
|
+
end
|
152
|
+
|
153
|
+
def wait_while_present(id)
|
154
|
+
browser.element(:id=>id).wait_while_present
|
155
|
+
end
|
156
|
+
|
157
|
+
def wait_until(&block)
|
158
|
+
browser.wait_until(&block)
|
159
|
+
end
|
160
|
+
|
161
|
+
def expect_path_to_be(path)
|
162
|
+
|
163
|
+
begin
|
164
|
+
if path.instance_of?(Regexp)
|
165
|
+
wait_until { current_path.match(path) != nil }
|
166
|
+
else
|
167
|
+
path = path.chomp('/')
|
168
|
+
wait_until { current_path == path }
|
169
|
+
end
|
170
|
+
rescue Watir::Wait::TimeoutError => e
|
171
|
+
raise Watir::Wait::TimeoutError, "Path is expected to be '#{path}', instead we got '#{current_path}'"
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
def exists?(*option)
|
177
|
+
browser.element(*option).exists?
|
178
|
+
end
|
179
|
+
|
180
|
+
def execute_script(js)
|
181
|
+
browser.execute_script(js)
|
182
|
+
end
|
183
|
+
|
184
|
+
def wait_for_ajax
|
185
|
+
begin
|
186
|
+
wait_until { browser.execute_script "return jQuery.active == 0" }
|
187
|
+
rescue Selenium::WebDriver::Error::UnexpectedJavascriptError
|
188
|
+
# do nothing
|
189
|
+
rescue Watir::Wait::TimeoutError => e
|
190
|
+
raise Watir::Wait::TimeoutError, "Ajax is taking too long"
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|