forked from refinery/refinerycms-page-images
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'complistic-gaff/rails-4-strong-parameters'
Conflicts: refinerycms-page-images.gemspec
- Loading branch information
Showing
5 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
app/decorators/controllers/refinery/admin/pages_controller_decorator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Refinery::Admin::PagesController.class_eval do | ||
|
||
# We need to add :images_attributes to page_params as it is ignored by strong parameters. (See #100) | ||
def page_params_with_page_image_params | ||
|
||
# Get the :images_attributes hash from params | ||
page_image_params = params.require(:page).permit(images_attributes: [:id, :caption]) | ||
|
||
# If there is no :images_attributes hash use a blank hash (so it removes deleted images) | ||
page_image_params = {images_attributes:{}} if page_image_params[:images_attributes].nil? | ||
|
||
# Add the :images_attributes hash to the default page_params hash | ||
page_params_without_page_image_params.merge(page_image_params) | ||
|
||
end | ||
|
||
# Swap out the default page_params method with our new one | ||
alias_method_chain :page_params, :page_image_params | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
require "spec_helper" | ||
|
||
describe "page images" do | ||
refinery_login_with :refinery_user | ||
|
||
let(:configure) {} | ||
let(:page_for_images) { FactoryGirl.create(:page) } | ||
let(:image) { FactoryGirl.create(:image) } | ||
let(:navigate_to_edit) { visit refinery.edit_admin_page_path(page_for_images) } | ||
let(:page_images_tab_id) { "#custom_#{::I18n.t(:'refinery.plugins.refinery_page_images.tab_name')}_tab" } | ||
|
||
let(:setup_and_visit) do | ||
configure | ||
page_for_images | ||
navigate_to_edit | ||
end | ||
|
||
# Regression test for #100 and #102 | ||
it "can add a page image to the db", :js => true do | ||
|
||
image | ||
setup_and_visit | ||
|
||
page_for_images.images.count.should eq 0 | ||
|
||
page.find("#{page_images_tab_id} a").click | ||
|
||
# Add the first Image | ||
click_link "Add Image" | ||
|
||
page.should have_selector 'iframe#dialog_iframe' | ||
page.within_frame('dialog_iframe') do | ||
find(:css, "#existing_image_area img#image_#{image.id}").click | ||
click_button ::I18n.t('button_text', :scope => 'refinery.admin.images.existing_image') | ||
end | ||
|
||
# image should be visable on the page | ||
page.should have_selector("#page_images li#image_#{image.id}") | ||
|
||
click_button "Save" | ||
|
||
# image should be in the db | ||
page_for_images.images.count.should eq 1 | ||
|
||
end | ||
|
||
context "with images" do | ||
|
||
let(:page_for_images) { FactoryGirl.create(:page_with_image) } | ||
|
||
# Regression test for #100 and #102 | ||
it "can remove a page image to the db", :js => true do | ||
|
||
setup_and_visit | ||
|
||
page_for_images.images.count.should eq 1 | ||
|
||
page.find("#{page_images_tab_id} a").click | ||
|
||
page.should have_selector("#page_images li#image_#{page_for_images.images.first.id}") | ||
|
||
image_li_tag = page.find("#page_images li:first-child") | ||
image_li_tag.hover | ||
within(image_li_tag) { page.find('img:first-child').click } | ||
|
||
page.should_not have_selector("#page_images li#image_#{page_for_images.images.first.id}") | ||
|
||
click_button "Save" | ||
|
||
page_for_images.images.count.should eq 0 | ||
|
||
end | ||
end | ||
|
||
end | ||
|