Skip to content

Commit

Permalink
Merge pull request #2710 from refinery/fix-intermittent-build-failures
Browse files Browse the repository at this point in the history
Fixed intermittent build failures by looking for both image title selectors
  • Loading branch information
parndt committed Oct 20, 2014
2 parents cba3e04 + f539410 commit beccdc8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 31 deletions.
2 changes: 1 addition & 1 deletion images/app/views/refinery/admin/images/_grid_view.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ul id="image_grid" class="<%= ['clearfix', 'pagination_frame', pagination_css_class].compact.join(' ') %>">
<ul id="image_grid" class="<%= ['clearfix', 'pagination_frame', 'images_list', pagination_css_class].compact.join(' ') %>">
<% @images.each_with_index do |image, index| -%>
<li id="image_<%= image.id %>" class="image_<%= index % 5 %>">
<%= image_fu image, '135x135#c', title: image.title %>
Expand Down
2 changes: 1 addition & 1 deletion images/app/views/refinery/admin/images/_list_view.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<% date_time = (image_group = container.last).first.created_at %>
<% date = Date.parse(date_time.to_s) %>
<h3><%= l(date, format: :long ) %></h3>
<ul>
<ul class='images_list'>
<%= render partial: 'list_view_image', collection: image_group %>
</ul>
<% end %>
Expand Down
20 changes: 6 additions & 14 deletions images/spec/features/refinery/admin/images_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,20 @@ module Refinery

context 'when there is one image' do
let!(:image) { FactoryGirl.create(:image) }
let(:initial_path) { refinery.admin_images_path(view: %w(grid list).sample) }

it_behaves_like 'an image index' do
before {visit refinery.admin_images_path}
end

it_behaves_like 'an image deleter' do #deletes an image
before {visit refinery.admin_images_path}
end
it_behaves_like 'an image index'
it_behaves_like 'an image deleter'
end

context 'when there are many images' do
let!(:image) { FactoryGirl.create(:image) }
let!(:alt_image) { FactoryGirl.create(:alternate_image) }
let!(:another_image) { FactoryGirl.create(:another_image) }
let(:initial_path) { refinery.admin_images_path(view: %w(grid list).sample) }

it_behaves_like 'an image index' do
before {visit refinery.admin_images_path}
end

it_behaves_like 'an image deleter' do
before {visit refinery.admin_images_path}
end
it_behaves_like 'an image index'
it_behaves_like 'an image deleter'
end

end # Admin Images Tab
Expand Down
35 changes: 20 additions & 15 deletions images/spec/support/shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ def ensure_on(path)
visit(path) unless current_path == path
end

shared_examples_for 'an image index' do |initial_path|
shared_examples_for 'an image index' do

let(:image_count) {[Refinery::Image.count, Refinery::Images.pages_per_admin_index].min}

before do
raise "please set let(:initial_path)" if initial_path.blank?
ensure_on(initial_path)
end

Expand All @@ -30,9 +31,7 @@ def ensure_on(path)

context "when in grid view" do

before do
ensure_on(current_path + "?view=grid")
end
before { ensure_on(current_path + "?view=grid") }

it 'shows the images with thumbnails' do
expect(page).to have_selector('#records li>img', count: image_count)
Expand Down Expand Up @@ -62,8 +61,8 @@ def ensure_on(path)

end # list view

describe 'pagination', unless: Refinery::Image.count<=2 do
Refinery::Images.pages_per_admin_index=2
describe 'pagination', unless: Refinery::Image.count <= 2 do
before { Refinery::Images.pages_per_admin_index = 2 }

it 'divides the index into pages' do
expect(page).to have_selector("div.pagination em.current")
Expand Down Expand Up @@ -94,26 +93,32 @@ def ensure_on(path)
end # pagination
end # image index

shared_examples_for 'an image deleter' do |initial_path|

before do
shared_examples_for 'an image deleter' do
before do
raise "please set let(:initial_path)" if initial_path.blank?
ensure_on(initial_path)
end
let(:deleting_an_image) { -> { first("#records li").click_link(::I18n.t('delete', scope: 'refinery.admin.images')) } }

it 'has a delete image link for each image' do
let(:deleting_an_image) {
-> {
first("#records li").click_link(::I18n.t('delete', scope: 'refinery.admin.images'))
}
}

it 'has a delete image link for each image' do
pending
end

it "removes an image" do
expect(deleting_an_image).to change(Refinery::Image, :count).by(-1)
end

it 'says the image has been removed' do
expect(page).to have_selector("#records li.image_0")
image_list_item = find("#records li.image_0")
image_title = image_list_item.first("img")[:title]
first("#records li").click_link(::I18n.t('delete', scope: 'refinery.admin.images'))
expect(page).to have_selector(".images_list li:first")
image_title = find(".images_list li:first").first("img")[:title] || # grid view
find(".images_list li:first").first("span.title").text # list view
expect(image_title).to be_present
first(".images_list li:first").click_link(::I18n.t('delete', scope: 'refinery.admin.images'))
expect(page).to have_content(::I18n.t('destroyed', scope: 'refinery.crudify', what: "'#{image_title}'"))
end

Expand Down

0 comments on commit beccdc8

Please sign in to comment.