Skip to content

Commit

Permalink
Merge 53e5c09 into 61578ce
Browse files Browse the repository at this point in the history
  • Loading branch information
anitagraham committed Sep 10, 2014
2 parents 61578ce + 53e5c09 commit 8f336e1
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 203 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -88,4 +88,5 @@ public/assets
Gemfile.lock

# Local Gemfile for developing without sharing dependencies
.gemfile
.gemfile
*.txt
Expand Up @@ -3,8 +3,9 @@
<%= list_view_image.title %>
</span>
<span class='alt'>
<%= refinery_icon_tag('information', title: "Alt text: #{list_view_image.alt}") %>
<%= link_to refinery_icon_tag('information'), '#', title: "Title: #{list_view_image.title} Alt text: #{list_view_image.alt}" %>
</span>

<span class="preview">&nbsp;</span>
<span class="actions">
<%= link_to refinery_icon_tag('eye'), list_view_image.url,
Expand All @@ -23,3 +24,4 @@
method: :delete %>
</span>
</li>

4 changes: 4 additions & 0 deletions images/spec/factories/image.rb
Expand Up @@ -6,4 +6,8 @@
factory :alternate_image, :class => ::Refinery::Image do
image Refinery.roots('refinery/images').join("spec/fixtures/beach-alternate.jpeg")
end

factory :another_image, :class => ::Refinery::Image do
image Refinery.roots('refinery/images').join("spec/fixtures/fathead.png")
end
end
229 changes: 28 additions & 201 deletions images/spec/features/refinery/admin/images_spec.rb
@@ -1,227 +1,54 @@
require "spec_helper"

module Refinery
describe "AdminImages", type: :feature do

describe "Admin Images Tab", type: :feature do
refinery_login_with :refinery_user

context "when no images" do
it "invites to add one" do
context 'when there are no images' do
it 'says there are no images'do
visit refinery.admin_images_path
expect(page).to have_content(::I18n.t('no_images_yet', scope: 'refinery.admin.images.records'))
end
end

it "shows add new image link" do
visit refinery.admin_images_path
expect(page).to have_content(::I18n.t('create_new_image', scope: 'refinery.admin.images.actions'))
expect(page).to have_selector("a[href*='#{refinery.new_admin_image_path}']")
end

context "new/create" do
it "uploads image with default title and alt text", js: true do
visit refinery.admin_images_path

click_link ::I18n.t('create_new_image', scope: 'refinery.admin.images.actions')

expect(page).to have_selector 'iframe#dialog_iframe'

page.within_frame('dialog_iframe') do
attach_file "image_image", Refinery.roots('refinery/images').
join("spec/fixtures/image-with-dashes.jpg")
click_button ::I18n.t('save', scope: 'refinery.admin.form_actions')
end

expect(page).to have_content(::I18n.t('created', scope: 'refinery.crudify', what: "'Image With Dashes'"))
expect(Refinery::Image.where(image_title: 'Image With Dashes', image_alt: '')).to exist
expect(Refinery::Image.count).to eq(1)
end

it "uploads image with specific title and alt text", js: true do
visit refinery.admin_images_path

click_link ::I18n.t('create_new_image', scope: 'refinery.admin.images.actions')

expect(page).to have_selector 'iframe#dialog_iframe'

page.within_frame('dialog_iframe') do
attach_file "image_image", Refinery.roots('refinery/images').
join("spec/fixtures/image-with-dashes.jpg")
fill_in 'image_image_title', with: 'Image Title'
fill_in 'image_image_alt', with: 'Alt Text'

click_button ::I18n.t('save', scope: 'refinery.admin.form_actions')
end

expect(page).to have_content(::I18n.t('created', scope: 'refinery.crudify', what: "'Image Title'"))
expect(Refinery::Image.where(image_title: 'Image Title', image_alt: 'Alt Text')).to exist
expect(Refinery::Image.count).to eq(1)

end

it "cannot upload a pdf", js: true do
visit refinery.admin_images_path

click_link ::I18n.t('create_new_image', scope: 'refinery.admin.images.actions')

expect(page).to have_selector 'iframe#dialog_iframe'
context 'when there is one image' do
let!(:image) { FactoryGirl.create(:image) }

page.within_frame('dialog_iframe') do
attach_file "image_image", Refinery.roots('refinery/images').
join("spec/fixtures/cape-town-tide-table.pdf")
click_button ::I18n.t('save', scope: 'refinery.admin.form_actions')
it_behaves_like 'an image index' do
before {visit refinery.admin_images_path}
end

page.within_frame('dialog_iframe') do
expect(page).to have_content(::I18n.t('incorrect_format', scope: 'activerecord.errors.models.refinery/image'))
it_behaves_like 'an image deleter' do #deletes an image
before {visit refinery.admin_images_path}
end
expect(Refinery::Image.count).to eq(0)
end
end

context "new/create - insert mode" do
it "uploads image", :js => true do
visit refinery.insert_admin_images_path(:modal => true)

attach_file "image_image", Refinery.roots('refinery/images').join("spec/fixtures/image-with-dashes.jpg")
click_button ::I18n.t('save', scope: 'refinery.admin.form_actions')

expect(page).to have_selector('#existing_image_area', visible: true)
expect(Refinery::Image.count).to eq(1)
end

it "gets error message when uploading non-image", :js => true do
visit refinery.insert_admin_images_path(:modal => true)

attach_file "image_image", Refinery.roots('refinery/images').join("spec/fixtures/cape-town-tide-table.pdf")
click_button ::I18n.t('save', scope: 'refinery.admin.form_actions')

expect(page).to have_selector('#upload_image_area', visible: true)
expect(page).to have_content(::I18n.t('incorrect_format', scope: 'activerecord.errors.models.refinery/image'))
expect(Refinery::Image.count).to eq(0)
end

it "gets error message when uploading non-image (when an image already exists)", js: true do
FactoryGirl.create(:image)
visit refinery.insert_admin_images_path(:modal => true)

choose 'Upload'
attach_file "image_image", Refinery.roots('refinery/images').join("spec/fixtures/cape-town-tide-table.pdf")
click_button ::I18n.t('save', scope: 'refinery.admin.form_actions')

expect(page).to have_selector('#upload_image_area', visible: true)
expect(page).to have_content(::I18n.t('incorrect_format', scope: 'activerecord.errors.models.refinery/image'))
expect(Refinery::Image.count).to eq(1)
end
end

context "when an image exists" do
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) }

context "edit/update" do
it "updates image" do
visit refinery.admin_images_path
expect(page).to have_selector("a[href='#{refinery.edit_admin_image_path(image)}']")

click_link ::I18n.t('edit', scope: 'refinery.admin.images')

expect(page).to have_content("Use current image or replace it with this one...")
expect(page).to have_selector("a[href*='#{refinery.admin_images_path}']")

attach_file "image_image", Refinery.roots('refinery/images').join("spec/fixtures/beach.jpeg")
click_button ::I18n.t('save', scope: 'refinery.admin.form_actions')

expect(page).to have_content(::I18n.t('updated', scope: 'refinery.crudify', what: "'Beach'"))
expect(Refinery::Image.count).to eq(1)

expect { click_link "View this image" }.not_to raise_error
end

it "doesn't allow updating if image has different file name" do
visit refinery.edit_admin_image_path(image)

attach_file "image_image", Refinery.roots('refinery/images').join("spec/fixtures/fathead.png")
click_button ::I18n.t('save', scope: 'refinery.admin.form_actions')

expect(page).to have_content(::I18n.t("different_file_name",
scope: "activerecord.errors.models.refinery/image"))
end
end

context "page" do
# Regression test for #2552 (https://github.com/refinery/refinerycms/issues/2552)
let :page_for_image do
page = Refinery::Page.create title: "Add Image to me"
# we need page parts so that there's a visual editor
Refinery::Pages.default_parts.each_with_index do |default_page_part, index|
page.parts.create(title: default_page_part, body: nil, position: index)
end
page
end
it "can add an image to a page and update the image", js: true do
visit refinery.edit_admin_page_path(page_for_image)

# add image to the page
expect(page.body).to match(/Add Image/)
click_link 'Add Image'
expect(page).to have_selector 'iframe#dialog_frame'
page.within_frame('dialog_frame') do
find(:css, "#existing_image_area img#image_#{image.id}").click
find(:css, '#existing_image_size_area #image_dialog_size_0').click
click_button ::I18n.t('button_text', scope: 'refinery.admin.images.existing_image')
end
click_button "Save"

# check that image loads after it has been updated
visit refinery.url_for(page_for_image.url)
visit find(:css, 'img[src^="/system/images"]')[:src]
expect(page).to have_css('img[src*="/system/images"]')
expect { page }.to_not have_content('Not found')

# update the image
visit refinery.edit_admin_image_path(image)
attach_file "image_image", Refinery.roots('refinery/images').join("spec/fixtures/beach.jpeg")
click_button "Save"

# check that image loads after it has been updated
visit refinery.url_for(page_for_image.url)
visit find(:css, 'img[src^="/system/images"]')[:src]
expect(page).to have_css('img[src*="/system/images"]')
expect { page }.to_not have_content('Not found')
end
it_behaves_like 'an image index' do
before {visit refinery.admin_images_path}
end

context "destroy" do
it "removes image" do
visit refinery.admin_images_path
expect(page).to have_selector("a[href='#{refinery.admin_image_path(image)}']")

click_link ::I18n.t('delete', scope: 'refinery.admin.images')

expect(page).to have_content(::I18n.t('destroyed', scope: 'refinery.crudify', what: "'Beach'"))
expect(Refinery::Image.count).to eq(0)
end
it_behaves_like 'an image deleter' do
before {visit refinery.admin_images_path}
end
end

context "download" do
it "succeeds" do
visit refinery.admin_images_path
end # Admin Images Tab

expect { click_link "View this image" }.not_to raise_error
end
end
describe 'Page Edit Images tab' do
# it_behaves_like 'an image uploader'
# it behaves_like 'an image editor'
# it behaves_like 'an image previewer'
# it_behaves_like 'an image index'
# it behaves_like 'an image inserter'
# it behaves_like 'an image deleter'
end

describe "switch view" do
it "shows images in grid" do
visit refinery.admin_images_path
expect(page).to have_content(::I18n.t('switch_to', view_name: 'list', scope: 'refinery.admin.images.index.view'))
expect(page).to have_selector("a[href='#{refinery.admin_images_path(view: 'list')}']")
end # Module Refinery

click_link "Switch to list view"

expect(page).to have_content(::I18n.t('switch_to', view_name: 'grid', scope: 'refinery.admin.images.index.view'))
expect(page).to have_selector("a[href='#{refinery.admin_images_path(view: 'grid')}']")
end
end
end
end
end

0 comments on commit 8f336e1

Please sign in to comment.