noosfero_steps.rb
21.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
def selenium_driver?
  self.class.to_s == 'Webrat::SeleniumSession'
end
Given /^the following users?$/ do |table|
  # table is a Cucumber::Ast::Table
  table.hashes.each do |item|
    person_data = item.dup
    person_data.delete("login")
    category = Category.find_by_slug person_data.delete("category")
    user = User.create!(:login => item[:login], :password => '123456', :password_confirmation => '123456', :email => item[:login] + "@example.com", :person_data => person_data)
    user.activate
    p = user.person
    p.categories << category if category
    p.save!
    user.save!
  end
end
Given /^"(.+)" is (invisible|visible)$/ do |user, visibility|
  User.find_by_login(user).person.update_attributes(:visible => (visibility == 'visible'))
end
Given /^"(.+)" is (online|offline|busy) in chat$/ do |user, status|
  status = {'online' => 'chat', 'offline' => '', 'busy' => 'dnd'}[status]
  User.find_by_login(user).update_attributes(:chat_status => status, :chat_status_at => DateTime.now)
end
Given /^the following (community|communities|enterprises?|organizations?)$/ do |kind,table|
  klass = kind.singularize.camelize.constantize
  table.hashes.each do |row|
    owner = row.delete("owner")
    domain = row.delete("domain")
    category = row.delete("category")
    img_name = row.delete("img")
    organization = klass.create!(row)
    if owner
      organization.add_admin(Profile[owner])
    end
    if domain
      d = Domain.new :name => domain, :owner => organization
      d.save(false)
    end
    city = row.delete("city")
    if city
      c = City.find_by_name city
      organization.region = c
    end
    if category && !category.blank?
      cat = Category.find_by_slug category
      organization.categories << cat
    end
    if img_name
      img = Image.create!(:uploaded_data => fixture_file_upload('/files/'+img_name+'.png', 'image/png'))
      organization.image = img
    end
    organization.save!
  end
end
Given /^"([^\"]*)" is associated with "([^\"]*)"$/ do |enterprise, bsc|
  enterprise = Enterprise.find_by_name(enterprise) || Enterprise[enterprise]
  bsc = BscPlugin::Bsc.find_by_name(bsc) || BscPlugin::Bsc[bsc]
  bsc.enterprises << enterprise
end
Then /^"([^\"]*)" should be associated with "([^\"]*)"$/ do |enterprise, bsc|
  enterprise = Enterprise.find_by_name(enterprise) || Enterprise[enterprise]
  bsc = BscPlugin::Bsc.find_by_name(bsc) || BscPlugin::Bsc[bsc]
  bsc.enterprises.should include(enterprise)
end
Given /^the folllowing "([^\"]*)" from "([^\"]*)"$/ do |kind, plugin, table|
  klass = (plugin.camelize+'::'+kind.singularize.camelize).constantize
  table.hashes.each do |row|
    owner = row.delete("owner")
    domain = row.delete("domain")
    organization = klass.create!(row)
    if owner
      organization.add_admin(Profile[owner])
    end
    if domain
      d = Domain.new :name => domain, :owner => organization
      d.save(false)
    end
  end
end
Given /^the following blocks$/ do |table|
  table.hashes.map{|item| item.dup}.each do |item|
    klass = item.delete('type')
    owner_type = item.delete('owner')
    owner = owner_type == 'environment' ? Environment.default : Profile[owner_type]
    if owner.boxes.empty?
      owner.boxes<< Box.new
      owner.boxes.first.blocks << MainBlock.new
    end
    box_id = owner.boxes.last.id
    klass.constantize.create!(item.merge(:box_id => box_id))
  end
end
Given /^the following (articles|events|blogs|folders|forums|galleries|uploaded files|rss feeds)$/ do |content, table|
  klass = {
    'articles' => TextileArticle,
    'events' => Event,
    'blogs' => Blog,
    'folders' => Folder,
    'forums' => Forum,
    'galleries' => Gallery,
    'uploaded files' => UploadedFile,
    'rss feeds' => RssFeed,
  }[content] || raise("Don't know how to build %s" % content)
  table.hashes.map{|item| item.dup}.each do |item|
    owner_identifier = item.delete("owner")
    parent = item.delete("parent")
    owner = Profile[owner_identifier]
    home = item.delete("homepage")
    language = item.delete("lang")
    category = item.delete("category")
    filename = item.delete("filename")
    translation_of_id = nil
    if item["translation_of"]
      if item["translation_of"] != "nil"
        article = owner.articles.find_by_name(item["translation_of"])
        translation_of_id = article.id if article
      end
      item.delete("translation_of")
    end
    item.merge!(
      :profile => owner,
      :language => language,
      :translation_of_id => translation_of_id)
      if !filename.blank?
        item.merge!(:uploaded_data => fixture_file_upload("/files/#{filename}.png", 'image/png'))
      end
      result = klass.new(item)
      if parent
        result.parent = Article.find_by_name(parent)
      end
      if category
        cat = Category.find_by_slug category
        if cat
          result.add_category(cat)
        end
      end
      result.save!
      if home == 'true'
        owner.home_page = result
        owner.save!
      end
  end
end
Given /^the following files$/ do |table|
  table.hashes.each do |item|
    owner = Profile[item[:owner]]
    file = "/files/#{item[:file]}"
    article = UploadedFile.new(:profile => owner, :uploaded_data => fixture_file_upload(file, item[:mime]))
    if item[:parent]
      article.parent = Article.find_by_slug(item[:parent])
    end
    article.save!
    if item[:homepage]
      owner.home_page = article
      owner.save!
    end
  end
end
Given /^the following articles? with images?$/ do |table|
  table.hashes.each do |item|
    owner = Profile[item[:owner]]
    file = item[:image]
    img = { :src => "/images/#{file}", :alt => file }
    img[:width] = item[:dimensions].split('x')[0] if item[:dimensions]
    img[:height] = item[:dimensions].split('x')[1] if item[:dimensions]
    img[:style] = item[:style] if item[:style]
    img_tag = "<img "
    img.each { |attr, value| img_tag += "#{attr}=\"#{value}\" " }
    img_tag += "/>"
    article = TinyMceArticle.new(:profile => owner, :name => item[:name], :body => img_tag)
    if item[:parent]
      article.parent = Article.find_by_slug(item[:parent])
    end
    article.save!
    if item[:homepage]
      owner.home_page = article
      owner.save!
    end
  end
end
Given /^the following products?$/ do |table|
  table.hashes.each do |item|
    data = item.dup
    owner = Enterprise[data.delete("owner")]
    category = Category.find_by_slug(data.delete("category").to_slug)
    data.merge!(:enterprise => owner, :product_category => category)
    if data[:img]
      img = Image.create!(:uploaded_data => fixture_file_upload('/files/'+data.delete("img")+'.png', 'image/png'))
      data.merge!(:image_id => img.id)
    end
    if data[:qualifier]
      qualifier = Qualifier.find_by_name(data.delete("qualifier"))
      data.merge!(:qualifiers => [qualifier])
    end
    product = Product.create!(data)
  end
end
Given /^the following inputs?$/ do |table|
  table.hashes.each do |item|
    data = item.dup
    product = Product.find_by_name(data.delete("product"))
    category = Category.find_by_slug(data.delete("category").to_slug)
    unit = Unit.find_by_singular(data.delete("unit"))
    solidary = data.delete("solidary")
    input = Input.create!(data.merge(:product => product, :product_category => category, :unit => unit,
                                     :is_from_solidarity_economy => solidary))
    input.update_attributes!(:position => data['position'])
  end
end
Given /^the following states$/ do |table|
  table.hashes.each do |item|
    data = item.dup
    if validator = Enterprise.find_by_name(data.delete("validator_name"))
      State.create!(data.merge(:environment => Environment.default, :validators => [validator]))
    else
      r = State.create!(data.merge(:environment => Environment.default))
    end
  end
end
Given /^the following validation info$/ do |table|
  table.hashes.each do |item|
    data = item.dup
    organization = Organization.find_by_name(data.delete("organization_name"))
    ValidationInfo.create!(data.merge(:organization => organization))
  end
end
Given /^the following (product_categories|product_category|category|categories|regions?)$/ do |kind,table|
  klass = kind.singularize.camelize.constantize
  table.hashes.each do |row|
    parent = row.delete("parent")
    if parent
      parent = Category.find_by_slug(parent.to_slug)
      row.merge!({:parent_id => parent.id})
    end
    category = klass.create!({:environment_id => Environment.default.id}.merge(row))
  end
end
Given /^the following qualifiers$/ do |table|
  table.hashes.each do |row|
    Qualifier.create!(row.merge(:environment_id => 1))
  end
end
Given /^the following certifiers$/ do |table|
  table.hashes.each do |row|
    row = row.dup
    qualifiers_list = row.delete("qualifiers")
    if qualifiers_list
      row["qualifiers"] = qualifiers_list.split(', ').map{|i| Qualifier.find_by_name(i)}
    end
    Certifier.create!(row.merge(:environment_id => 1))
  end
end
Given /^the following production costs?$/ do |table|
  table.hashes.map{|item| item.dup}.each do |item|
    owner_type = item.delete('owner')
    owner = owner_type == 'environment' ? Environment.default : Profile[owner_type]
    ProductionCost.create!(item.merge(:owner => owner))
  end
end
Given /^the following price details?$/ do |table|
  table.hashes.map{|item| item.dup}.each do |item|
    product = Product.find_by_name item.delete('product')
    production_cost = ProductionCost.find_by_name item.delete('production_cost')
    product.price_details.create!(item.merge(:production_cost => production_cost))
  end
end
Given /^I am logged in as "(.+)"$/ do |username|
  visit('/account/logout')
  visit('/account/login')
  fill_in("Username", :with => username)
  fill_in("Password", :with => '123456')
  click_button("Log in")
  # FIXME selenium do not wait page load sometimes
  if selenium_driver?
    selenium.wait_for_page
  end
  Then "I should be logged in as \"#{username}\""
  @current_user = username
end
Given /^I am logged in as admin$/ do
  visit('/account/logout')
  user = User.create!(:login => 'admin_user', :password => '123456', :password_confirmation => '123456', :email => 'admin_user@example.com')
  user.activate
  e = Environment.default
  e.add_admin(user.person)
  visit('/account/login')
  fill_in("Username", :with => user.login)
  fill_in("Password", :with => '123456')
  click_button("Log in")
  # FIXME selenium do not wait page load sometimes
  if selenium_driver?
    selenium.wait_for_page
  end
end
Given /^I am not logged in$/ do
  visit('/account/logout')
end
Given /^feature "(.+)" is (enabled|disabled) on environment$/ do |feature, status|
  e = Environment.default
  status.chop!
  e.send status, feature
  e.save
end
Given /^organization_approval_method is "(.+)" on environment$/ do |approval_method|
  e = Environment.default
  e.organization_approval_method = approval_method
  e.save
end
Given /^"(.+)" is a member of "(.+)"$/ do |person,profile|
  Profile.find_by_name(profile).add_member(Profile.find_by_name(person))
end
Then /^"(.+)" should be a member of "(.+)"$/ do |person,profile|
  Profile.find_by_name(profile).members.should include(Person.find_by_name(person))
end
When /^"(.*)" is accepted on community "(.*)"$/ do |person, community|
  person = Person.find_by_name(person)
  community = Community.find_by_name(community)
  community.affiliate(person, Profile::Roles.member(community.environment.id))
end
Given /^"(.+)" is admin of "(.+)"$/ do |person, organization|
  org = Profile.find_by_name(organization)
  user = Profile.find_by_name(person)
  org.add_admin(user)
end
Then /^"(.+)" should be admin of "(.+)"$/ do |person, organization|
  org = Organization.find_by_name(organization)
  user = Person.find_by_name(person)
  org.admins.should include(user)
end
Then /^"(.+)" should be moderator of "(.+)"$/ do |person,profile|
  profile = Profile.find_by_name(profile)
  person = Person.find_by_name(person)
  profile.members_by_role(Profile::Roles.moderator(profile.environment.id)).should include(person)
end
Given /^"([^\"]*)" has no articles$/ do |profile|
  (Profile[profile] || Profile.find_by_name(profile)).articles.delete_all
end
Given /^the following (\w+) fields are (\w+) fields$/ do |klass, status, table|
  env = Environment.default
  fields = table.raw.inject({}) do |hash, line|
    hash[line.first] = {}
    hash[line.first].merge!({ "active" => 'true' })   if status == "active"
    hash[line.first].merge!({ "required" => 'true'})  if status == "required"
    hash[line.first].merge!({ "signup" => 'true'})    if status == "signup"
    hash
  end
  env.send("custom_#{klass.downcase}_fields=", fields)
  env.save!
  if fields.keys != env.send("#{status}_#{klass.downcase}_fields")
    raise "Not all fields #{status}! Requested: %s; #{status.camelcase}: %s" % [fields.keys.inspect, env.send("#{status}_#{klass.downcase}_fields").inspect]
  end
end
Then /^"([^\"]*)" should have the following data$/ do |id, table|
  profile = Profile.find_by_identifier(id)
  expected = table.hashes.first
  data = expected.keys.inject({}) { |hash, key| hash[key] = profile.send(key).to_s; hash }
  data.should == expected
end
Given /^(.+) is member of (.+)$/ do |person, group|
  Organization[group].add_member(Person[person])
end
Given /^"(.+)" is friend of "(.+)"$/ do |person, friend|
  Person[person].add_friend(Person[friend])
end
Given /^enterprise "([^\"]*)" is blocked$/ do |enterprise_name|
  enterprise = Enterprise.find_by_name(enterprise_name)
  enterprise.block
end
Given /^enterprise "([^\"]*)" is disabled$/ do |enterprise_name|
  enterprise = Enterprise.find_by_name(enterprise_name)
  enterprise.enabled = false
  enterprise.save
end
Then /^The page title should contain "(.*)"$/ do |text|
  if response.class.to_s == 'Webrat::SeleniumResponse'
    response.selenium.text('css=title').should include(text)
  else
    response.should have_selector("title:contains('#{text}')")
  end
end
Given /^the mailbox is empty$/ do
  ActionMailer::Base.deliveries = []
end
Given /^the (.+) mail (?:is|has) (.+) (.+)$/ do |position, field, value|
  if(/^[0-9]+$/ =~ position)
    ActionMailer::Base.deliveries[position.to_i][field] == value
  else
    ActionMailer::Base.deliveries.send(position)[field] == value
  end
end
Given /^the (.+) mail (.+) is like (.+)$/ do |position, field, regexp|
  re = Regexp.new(regexp)
  if(/^[0-9]+$/ =~ position)
    re =~ ActionMailer::Base.deliveries[position.to_i][field.to_sym]
  else
    re =~ ActionMailer::Base.deliveries.send(position)[field.to_sym]
  end
end
Given /^the following environment configuration$/ do |table|
  env = Environment.default
  table.raw.each do |item|
    env.send("#{item[0]}=", item[1])
  end
  env.save
end
Then /^I should be logged in as "(.+)"$/ do |login|
  User.find(session[:user]).login.should == login
end
Then /^I should not be logged in$/ do
  session[:user].nil?
end
Given /^the profile "(.+)" has no blocks$/ do |profile|
  profile = Profile[profile]
  profile.boxes.map do |box|
    box.blocks.destroy_all
  end
end
Given /^the articles of "(.+)" are moderated$/ do |organization|
  organization = Organization.find_by_name(organization)
  organization.moderated_articles = true
  organization.save
end
Given /^the following comments?$/ do |table|
  table.hashes.each do |item|
    data = item.dup
    article = Article.find_by_name(data.delete("article"))
    author = data.delete("author")
    comment = article.comments.build(data)
    if author
      comment.author = Profile[author]
    end
    comment.save!
  end
end
Given /^the community "(.+)" is closed$/ do |community|
  community = Community.find_by_name(community)
  community.closed = true
  community.save
end
Given /^someone suggested the following article to be published$/ do |table|
  table.hashes.map{|item| item.dup}.each do |item|
    target = Community[item.delete('target')]
    task = SuggestArticle.create!(:target => target, :data => item)
  end
end
Given /^the following units?$/ do |table|
  table.hashes.each do |row|
    Unit.create!(row.merge(:environment_id => 1))
  end
end
Given /^"([^\"]*)" asked to join "([^\"]*)"$/ do |person, organization|
  person = Person.find_by_name(person)
  organization = Organization.find_by_name(organization)
  AddMember.create!(:person => person, :organization => organization)
end
Given /^that the default environment have (.+) templates?$/ do |option|
  env = Environment.default
  case option
  when 'all profile'
    env.create_templates
  when 'no Inactive Enterprise'
    env.inactive_enterprise_template && env.inactive_enterprise_template.destroy
  end
end
Given /^the environment domain is "([^\"]*)"$/ do |domain|
  d = Domain.new :name => domain, :owner => Environment.default
  d.save(false)
end
When /^([^\']*)'s account is activated$/ do |person|
  Person.find_by_name(person).user.activate
end
Then /^I should receive an e-mail on (.*)$/ do |address|
  last_mail = ActionMailer::Base.deliveries.last
  last_mail['to'].to_s.should == address
end
Given /^"([^\"]*)" plugin is (enabled|disabled)$/ do |plugin_name, status|
  environment = Environment.default
  environment.send(status.chop + '_plugin', plugin_name+'Plugin')
end
Then /^there should be an? (.+) named "([^\"]*)"$/ do |klass_name, profile_name|
  klass = klass_name.camelize.constantize
  klass.find_by_name(profile_name).nil?.should be_false
end
Then /^"([^\"]*)" profile should exist$/ do |profile_selector|
  profile = nil
  begin
    profile = Profile.find_by_name(profile_selector)
    profile.nil?.should be_false
  rescue
    profile.nil?.should be_false
  end
end
Then /^"([^\"]*)" profile should not exist$/ do |profile_selector|
  profile = nil
  begin
    profile = Profile.find_by_name(profile_selector)
    profile.nil?.should be_true
  rescue
    profile.nil?.should be_true
  end
end
When 'I log off' do
  visit '/account/logout'
end
Then /^I should be taken to "([^\"]*)" product page$/ do |product_name|
  product = Product.find_by_name(product_name)
  path = url_for(product.enterprise.public_profile_url.merge(:controller => 'manage_products', :action => 'show', :id => product, :only_path => true))
  if response.class.to_s == 'Webrat::SeleniumResponse'
    URI.parse(response.selenium.get_location).path.should == path_to(path)
  else
    URI.parse(current_url).path.should == path_to(path)
  end
end
When /^I reload and wait for the page$/ do
  response.selenium.refresh
  selenium.wait_for_page
end
Given /^the following enterprise homepages?$/ do |table|
  # table is a Cucumber::Ast::Table
  table.hashes.each do |item|
    data = item.dup
    home = EnterpriseHomepage.new(:name => data[:name])
    ent = Enterprise.find_by_identifier(data[:enterprise])
    ent.articles << home
  end
end
And /^I want to add "([^\"]*)" as cost$/ do |string|
  selenium.answer_on_next_prompt(string)
end
Given /^([^\s]+) (enabled|disabled) translation redirection in (?:his|her) profile$/ do
  |login, status|
  profile = Profile[login]
  profile.redirect_l10n = ( status == "enabled" )
  profile.save
end
Given /^the search index is empty$/ do
  ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => '*:*'))
end
# This could be merged with "the following categories"
Given /^the following categories as facets$/ do |table|
  ids = []
  table.hashes.each do |item|
    cat = Category.find_by_name(item[:name])
    if cat.nil?
      cat = Category.create!(:environment_id => Environment.default.id, :name => item[:name])
    end
    ids << cat.id
  end
  env = Environment.default
  env.top_level_category_as_facet_ids = ids
  env.save!
end
Given /^the following cities$/ do |table|
  table.hashes.each do |item|
    state = State.find_by_acronym item[:state]
    if !state
      state = State.create!(:name => item[:state], :acronym => item[:state], :environment_id => Environment.default.id)
    end
    city = City.create!(:name => item[:name], :environment_id => Environment.default.id)
    city.parent = state
    city.save!
  end
end
When /^I edit my profile$/ do
  visit "/myprofile/#{@current_user}"
  click_link "Edit Profile"
end
Given /^the following tags$/ do |table|
  table.hashes.each do |item|
    article = Article.find_by_name item[:article]
    article.tag_list.add item[:name]
    article.save!
  end
end
When /^I search ([^\"]*) for "([^\"]*)"$/ do |asset, query|
  When %{I go to the search #{asset} page}
  And %{I fill in "query" with "#{query}"}
  And %{I press "Search"}
end
Then /^I should see ([^\"]*)'s product image$/ do |product_name|
  p = Product.find_by_name product_name
  path = url_for(p.enterprise.public_profile_url.merge(:controller => 'manage_products', :action => 'show', :id => p, :only_path => true))
  response.should have_selector("div[class~=\"zoomable-image\"] a[href=\"http://#{path}\"]")
end
Then /^I should not see ([^\"]*)'s product image$/ do |product_name|
  p = Product.find_by_name product_name
  path = url_for(p.enterprise.public_profile_url.merge(:controller => 'manage_products', :action => 'show', :id => p, :only_path => true))
  response.should_not have_selector("div[class~=\"zoomable-image\"] a[href=\"http://#{path}\"]")
end
Then /^I should see ([^\"]*)'s profile image$/ do |name|
  response.should have_selector("img[alt=\"#{name}\"]")
end
Then /^I should not see ([^\"]*)'s profile image$/ do |name|
  response.should_not have_selector("img[alt=\"#{name}\"]")
end
Then /^I should see ([^\"]*)'s content image$/ do |name|
  response.should have_selector("img[alt=\"#{name}\"]")
end
Then /^I should not see ([^\"]*)'s content image$/ do |name|
  response.should_not have_selector("img[alt=\"#{name}\"]")
end
Then /^I should see ([^\"]*)'s community image$/ do |name|
  response.should have_selector("img[alt=\"#{name}\"]")
end
Then /^I should not see ([^\"]*)'s community image$/ do |name|
  response.should_not have_selector("img[alt=\"#{name}\"]")
end
Given /^the article "([^\"]*)" is updated by "([^\"]*)"$/ do |article, person|
  a = Article.find_by_name article
  p = Person.find_by_name person
  a.last_changed_by = p
  a.save!
end
Given /^the cache is turned (on|off)$/ do |state|
  ActionController::Base.perform_caching = (state == 'on')
end
When /^I make a AJAX request to (.*)$/ do |page|
  header 'X-Requested-With', 'XMLHttpRequest'
  visit(path_to(page))
end