carrier 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/Gemfile +11 -7
  2. data/Rakefile +1 -1
  3. data/VERSION +1 -1
  4. data/app/controllers/carrier/messages_controller.rb +7 -2
  5. data/app/views/carrier/messages/_message.html.erb +1 -2
  6. data/app/views/carrier/messages/_reply.html.erb +2 -2
  7. data/app/views/carrier/messages/show.html.erb +0 -3
  8. data/carrier.gemspec +29 -23
  9. data/config/locales/carrier.en.yml +4 -0
  10. data/config/locales/carrier.ru.yml +4 -0
  11. data/lib/carrier/rails/engine.rb +1 -1
  12. data/spec/dummy/app/helpers/application_helper.rb +1 -0
  13. data/spec/dummy/app/views/devise/registrations/new.html.erb +3 -0
  14. data/spec/dummy/app/views/layouts/application.html.erb +1 -1
  15. data/spec/dummy/config/cucumber.yml +8 -0
  16. data/spec/dummy/config/database.yml +2 -2
  17. data/spec/dummy/config/environments/test.rb +2 -0
  18. data/spec/dummy/db/schema.rb +12 -12
  19. data/spec/dummy/factories/message.rb +9 -0
  20. data/spec/dummy/factories/user.rb +13 -0
  21. data/spec/dummy/features/carrier.feature +79 -0
  22. data/spec/dummy/features/step_definitions/debug_steps.rb +15 -0
  23. data/spec/dummy/features/step_definitions/resources_steps.rb +15 -0
  24. data/spec/dummy/features/step_definitions/web_steps.rb +301 -0
  25. data/spec/dummy/features/support/carrier_routes_helper.rb +5 -0
  26. data/spec/dummy/features/support/env.rb +47 -0
  27. data/spec/dummy/features/support/paths.rb +34 -0
  28. data/spec/dummy/features/support/rails_helper.rb +50 -0
  29. data/spec/dummy/features/support/singleton.rb +17 -0
  30. data/spec/dummy/features/support/transaction.rb +30 -0
  31. data/spec/dummy/lib/tasks/cucumber.rake +65 -0
  32. data/spec/dummy/script/cucumber +10 -0
  33. data/spec/dummy_spec_helper.rb +12 -26
  34. metadata +189 -136
  35. data/TODO +0 -1
  36. data/script/rails +0 -6
  37. data/spec/integration/carrier_spec.rb +0 -73
  38. data/test/helper.rb +0 -18
  39. data/test/test_carrier.rb +0 -7
@@ -0,0 +1,15 @@
1
+ When /^I dump.* the response$/ do
2
+ puts page.body
3
+ end
4
+
5
+ Then /^show me the page$/ do
6
+ save_and_open_page
7
+ end
8
+
9
+ Then /^puts me the page$/ do
10
+ puts page.body
11
+ end
12
+
13
+ Then /^debug$/ do
14
+ true
15
+ end
@@ -0,0 +1,15 @@
1
+ Given /^There is (?:a\s)?(.*)(?:\swith (.*))/ do |resource, params|
2
+
3
+ # Rails.logger.info "--- #{params}"
4
+ resource = resource.scan(/\w+/).join('_')
5
+ attributes = {}
6
+
7
+ begin
8
+ pairs = params.scan(/(\w+)\s"(.*?)"(?:,\s|and\s)?/)
9
+ raise "Somethings wrong with arguments parsing. Check scenarios!" if pairs.any? {|el| el.nil? }
10
+ attributes = Hash[pairs]
11
+ end if params
12
+
13
+ res = instance_variable_set :"@#{resource}", singleton(:"#{resource}", attributes)
14
+ # Rails.logger.info("created resource - #{res.inspect}")
15
+ end
@@ -0,0 +1,301 @@
1
+ # encoding: UTF-8
2
+
3
+ # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
4
+ # It is recommended to regenerate this file in the future when you upgrade to a
5
+ # newer version of cucumber-rails. Consider adding your own code to a new file
6
+ # instead of editing this one. Cucumber will automatically load all features/**/*.rb
7
+ # files.
8
+ require 'uri'
9
+ require 'cgi'
10
+ require 'require_all'
11
+
12
+ module VariousHelpers
13
+ def with_scope(locator)
14
+ locator ? within(locator) { yield } : yield
15
+ end
16
+
17
+ def confirm_dialog page = page, message = nil
18
+ alert = page.driver.browser.switch_to.alert
19
+
20
+ if message.nil? || alert.text == message
21
+ alert.accept
22
+ else
23
+ alert.dismiss
24
+ end
25
+ end
26
+
27
+ def login_user user
28
+ visit "/"
29
+
30
+ fill_in "user_login", :with => user.username
31
+ fill_in "user_password", :with => user.password
32
+
33
+ click_button "Войти"
34
+ end
35
+ end
36
+
37
+ World(VariousHelpers)
38
+
39
+ Then /^got it$/ do
40
+ raise "got it"
41
+ end
42
+
43
+ When /I confirm dialog/ do
44
+ confirm_dialog
45
+ end
46
+
47
+ When /I wait for (\d*) seconds/ do |seconds|
48
+ sleep seconds.to_i
49
+ end
50
+
51
+ Given /I am not logged in/ do
52
+ visit '/users/sign_out'
53
+ visit '/'
54
+ end
55
+
56
+ Given /I am logged in as (\w*)(?:\swith username "([^"]*)")?$/ do |role, username|
57
+ params = {}
58
+ params.merge!(:username => username) if username
59
+
60
+ user = instance_variable_set(:"@#{role}", singleton(:"#{role}", params))
61
+ @javascript ? login_user(user) : login_as(user)
62
+ end
63
+
64
+ Given /^(?:|I )am on (.+)$/ do |page_name|
65
+ visit path_to(page_name)
66
+ end
67
+
68
+ When /^(?:|I )go to (.+)$/ do |page_name|
69
+ visit path_to(page_name)
70
+ end
71
+
72
+ And /I click "(.*)"/ do |title|
73
+ click_link title
74
+ end
75
+
76
+ And /I click on "(.*)"(?: within "([^"]*)")?$/ do |title, selector|
77
+ with_scope(selector) do
78
+ wait_until do
79
+ page.has_css? title
80
+ end
81
+
82
+ find(title).click
83
+ end
84
+ end
85
+
86
+ Given /^I click on button "([^"]*)"(?: within "([^"]*)")?$/ do |title, selector|
87
+ wait_until do
88
+ with_scope(selector) do
89
+ page.should have_xpath ".//a[contains(.,'#{title}')]"
90
+ end
91
+ end
92
+
93
+ with_scope(selector) do
94
+ find(:xpath, ".//a[contains(.,'#{title}')]").click
95
+ end
96
+
97
+ # find(:xpath, "//a[. = '#{arg1}']").click
98
+ end
99
+
100
+ Given /^I click on button with name$/ do |name|
101
+ find(:xpath, "//a[contains(.,'#{name}')]").click
102
+ end
103
+
104
+ When /^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/ do |button, selector|
105
+ with_scope(selector) do
106
+ click_button(button)
107
+ end
108
+ end
109
+
110
+ When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector|
111
+ with_scope(selector) do
112
+ click_link(link)
113
+ end
114
+ end
115
+
116
+ When /^(?:|I )fill in "([^"]*)" with "([^"]*)"(?: within "([^"]*)")?$/ do |field, value, selector|
117
+ with_scope(selector) do
118
+ fill_in(field, :with => value)
119
+ end
120
+ end
121
+
122
+ When /^(?:|I )fill in "([^"]*)" for "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
123
+ with_scope(selector) do
124
+ fill_in(field, :with => value)
125
+ end
126
+ end
127
+
128
+ # Use this to fill in an entire form with data from a table. Example:
129
+ #
130
+ # When I fill in the following:
131
+ # | Account Number | 5002 |
132
+ # | Expiry date | 2009-11-01 |
133
+ # | Note | Nice guy |
134
+ # | Wants Email? | |
135
+ #
136
+ # TODO: Add support for checkbox, select og option
137
+ # based on naming conventions.
138
+ #
139
+ When /^(?:|I )fill in the following(?: within "([^"]*)")?:$/ do |selector, fields|
140
+ with_scope(selector) do
141
+ fields.rows_hash.each do |name, value|
142
+ When %{I fill in "#{name}" with "#{value}"}
143
+ end
144
+ end
145
+ end
146
+
147
+ When /^(?:|I )select "([^"]*)" from "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
148
+ with_scope(selector) do
149
+ select(value, :from => field)
150
+ end
151
+ end
152
+
153
+ When /^(?:|I )check "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
154
+ with_scope(selector) do
155
+ check(field)
156
+ end
157
+ end
158
+
159
+ When /^(?:|I )uncheck "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
160
+ with_scope(selector) do
161
+ uncheck(field)
162
+ end
163
+ end
164
+
165
+ When /^(?:|I )choose "([^"]*)"(?: within "([^"]*)")?$/ do |field, selector|
166
+ with_scope(selector) do
167
+ choose(field)
168
+ end
169
+ end
170
+
171
+ When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"(?: within "([^"]*)")?$/ do |path, field, selector|
172
+ full_path = path.prepend "#{Rails.root}/features/fixtures/"
173
+ with_scope(selector) do
174
+ attach_file(field, full_path)
175
+ end
176
+ end
177
+
178
+ Then /^(?:|I )should see JSON:$/ do |expected_json|
179
+ require 'json'
180
+ expected = JSON.pretty_generate(JSON.parse(expected_json))
181
+ actual = JSON.pretty_generate(JSON.parse(response.body))
182
+ expected.should == actual
183
+ end
184
+
185
+ Then /^(?:|I )should see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
186
+
187
+ with_scope(selector) do
188
+ wait_until do
189
+ page.has_content? text
190
+ end
191
+
192
+ if page.respond_to? :should
193
+ page.should have_content(text)
194
+ else
195
+ assert page.has_content?(text)
196
+ end
197
+ end
198
+ end
199
+
200
+ Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
201
+ regexp = Regexp.new(regexp)
202
+ with_scope(selector) do
203
+ if page.respond_to? :should
204
+ page.should have_xpath('//*', :text => regexp)
205
+ else
206
+ assert page.has_xpath?('//*', :text => regexp)
207
+ end
208
+ end
209
+ end
210
+
211
+ Then /^(?:|I )should not see "([^\"]*)"(?: within "([^\"]*)")?$/ do |text, selector|
212
+ with_scope(selector) do
213
+ if page.respond_to? :should
214
+ page.should have_no_content(text)
215
+ else
216
+ assert page.has_no_content?(text)
217
+ end
218
+ end
219
+ end
220
+
221
+ Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
222
+ regexp = Regexp.new(regexp)
223
+ with_scope(selector) do
224
+ if page.respond_to? :should
225
+ page.should have_no_xpath('//*', :text => regexp)
226
+ else
227
+ assert page.has_no_xpath?('//*', :text => regexp)
228
+ end
229
+ end
230
+ end
231
+
232
+ Then /^the "([^"]*)" field(?: within "([^"]*)")? should contain "([^"]*)"$/ do |field, selector, value|
233
+ with_scope(selector) do
234
+ field = find_field(field)
235
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
236
+ if field_value.respond_to? :should
237
+ field_value.should =~ /#{value}/
238
+ else
239
+ assert_match(/#{value}/, field_value)
240
+ end
241
+ end
242
+ end
243
+
244
+ Then /^the "([^"]*)" field(?: within "([^"]*)")? should not contain "([^"]*)"$/ do |field, selector, value|
245
+ with_scope(selector) do
246
+ field = find_field(field)
247
+ field_value = (field.tag_name == 'textarea') ? field.text : field.value
248
+ if field_value.respond_to? :should_not
249
+ field_value.should_not =~ /#{value}/
250
+ else
251
+ assert_no_match(/#{value}/, field_value)
252
+ end
253
+ end
254
+ end
255
+
256
+ Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should be checked$/ do |label, selector|
257
+ with_scope(selector) do
258
+ field_checked = find_field(label)['checked']
259
+ if field_checked.respond_to? :should
260
+ field_checked.should be_true
261
+ else
262
+ assert field_checked
263
+ end
264
+ end
265
+ end
266
+
267
+ Then /^the "([^"]*)" checkbox(?: within "([^"]*)")? should not be checked$/ do |label, selector|
268
+ with_scope(selector) do
269
+ field_checked = find_field(label)['checked']
270
+ if field_checked.respond_to? :should
271
+ field_checked.should be_false
272
+ else
273
+ assert !field_checked
274
+ end
275
+ end
276
+ end
277
+
278
+ Then /^(?:|I )should be on (.+)$/ do |page_name|
279
+ current_path = URI.parse(current_url).path
280
+ if current_path.respond_to? :should
281
+ current_path.should == path_to(page_name)
282
+ else
283
+ assert_equal path_to(page_name), current_path
284
+ end
285
+ end
286
+
287
+ Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
288
+ query = URI.parse(current_url).query
289
+ actual_params = query ? CGI.parse(query) : {}
290
+ expected_params = {}
291
+ expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
292
+
293
+ if actual_params.respond_to? :should
294
+ actual_params.should == expected_params
295
+ else
296
+ assert_equal expected_params, actual_params
297
+ end
298
+ end
299
+
300
+
301
+
@@ -0,0 +1,5 @@
1
+ module CarrierRoutesHelper
2
+ include Carrier::Engine.routes.url_helpers
3
+ end
4
+
5
+ World(CarrierRoutesHelper)
@@ -0,0 +1,47 @@
1
+ ENV['RAILS_ENV'] = 'test'
2
+
3
+ require 'require_all'
4
+ require 'cucumber/rails'
5
+ require 'factory_girl_rails'
6
+ require_all File.expand_path File.dirname __FILE__
7
+
8
+ require File.expand_path("../../../config/environment.rb", __FILE__)
9
+
10
+ ENV["RAILS_ROOT"] ||= File.dirname(__FILE__) + "../../../spec/dummy"
11
+
12
+ ActionController::Base.allow_rescue = false
13
+
14
+ class ActiveRecord::Base
15
+ mattr_accessor :shared_connection
16
+ @@shared_connection = nil
17
+
18
+ def self.connection
19
+ @@shared_connection || retrieve_connection
20
+ end
21
+ end
22
+
23
+ ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
24
+
25
+ Cucumber::Rails::World.use_transactional_fixtures = true
26
+
27
+ Cucumber::Rails::Database.javascript_strategy = :shared_connection
28
+
29
+ include Warden::Test::Helpers
30
+ include FactoryGirl::Syntax::Methods
31
+
32
+ include SingletonHelper
33
+
34
+ include RailsHelper
35
+
36
+ migrate_if_needed
37
+ truncate_tables
38
+
39
+ Before do
40
+ Transaction.start
41
+ reset_singletons!
42
+ end
43
+
44
+ After do
45
+ Transaction.clean
46
+ Warden.test_reset!
47
+ end
@@ -0,0 +1,34 @@
1
+ module NavigationHelpers
2
+ def path_to(page_name)
3
+ case page_name
4
+
5
+ when /the home\s?page/
6
+ '/'
7
+ when /the sign in page/
8
+ new_user_session_path
9
+
10
+ when /Carrier's (main|'inbox') page/
11
+ messages_path
12
+
13
+ when /Carrier's 'sent' page/
14
+ sent_messages_path
15
+
16
+ when /new message path/
17
+ new_message_path
18
+
19
+ when /this message page/
20
+ message_path @message
21
+ else
22
+ begin
23
+ page_name =~ /the (.*) page/
24
+ path_components = $1.split(/\s+/)
25
+ self.send(path_components.push('path').join('_').to_sym)
26
+ rescue Object => e
27
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
28
+ "Now, go and add a mapping in #{__FILE__}"
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ World(NavigationHelpers)
@@ -0,0 +1,50 @@
1
+ require 'sugar-high/dsl'
2
+
3
+ module RailsHelper
4
+ def logger
5
+ Rails.logger
6
+ end
7
+
8
+ def migrate_if_needed
9
+ with ActiveRecord::Base.connection do
10
+ with ActiveRecord::Migrator do
11
+ migration_path = File.expand_path("#{Rails.root}/db/migrate", __FILE__)
12
+ migrate migration_path
13
+ end if tables.empty?
14
+ end
15
+ end
16
+
17
+ def truncate_tables
18
+ with ActiveRecord::Base.connection do
19
+ (tables - ['schema_migrations', 'roles']).map do |table|
20
+ table_count = execute("SELECT COUNT(*) FROM #{table}").first.first
21
+ execute "TRUNCATE #{table}" unless table_count == 0
22
+ end
23
+ end
24
+ end
25
+
26
+ def reload_files
27
+ ['app/models', 'app/controllers', :lib].each do |folder|
28
+ included_files = []
29
+ Dir["#{Rails.root}/#{folder}/**/*.rb"].each do |f|
30
+ begin
31
+ included_files << "#{f}"
32
+ load f
33
+ rescue => e
34
+ puts e.message
35
+ end
36
+ # puts "(Re)loaded files: " << included_files.inspect
37
+ end
38
+ end
39
+ end
40
+
41
+ def establish_connection
42
+ db_config = YAML.load(File.read(File.join(Rails.root, 'config','database.yml')))[ENV['RAILS_ENV']]
43
+
44
+ ActiveRecord::Base.establish_connection db_config
45
+ end
46
+
47
+ def drop_connection
48
+ ActiveRecord::Base.remove_connection
49
+ end
50
+ end