Skip to content

Commit

Permalink
Merge remote-tracking branch 'complistic-gaff/rails-4-strong-parameters'
Browse files Browse the repository at this point in the history
Conflicts:
	refinerycms-page-images.gemspec
  • Loading branch information
parndt committed Oct 11, 2014
2 parents 8ab9011 + 99949a5 commit cfe5e49
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 1 deletion.
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
1 change: 0 additions & 1 deletion app/views/refinery/admin/pages/tabs/_images_field.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<% modal_class = Refinery::PageImages.config.wysiwyg ? 'wym' : 'plain' %>

<div class='wym_box field images_field'>
<%= hidden_field_tag "#{f.object_name.demodulize}[images_attributes][-1]", "" %>
<ul id='page_images' class='clearfix'>
<%= f.fields_for :images do |image_form| %>
<li id='image_<%= image_form.object.id %>'>
Expand Down
4 changes: 4 additions & 0 deletions lib/refinery/page_images.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def attach!
end

Refinery::Image.send :has_many, :image_pages, :dependent => :destroy

# dosnt work wothout this...
require root.join('app/decorators/controllers/refinery/admin/pages_controller_decorator.rb')

end
end

Expand Down
1 change: 1 addition & 0 deletions refinerycms-page-images.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- spec/*`.split("\n")

s.add_dependency 'refinerycms-pages', '~> 3.0.0'
s.add_dependency 'decorators', '~> 1.0.0'
end
76 changes: 76 additions & 0 deletions spec/features/admin/page_images_spec.rb
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

0 comments on commit cfe5e49

Please sign in to comment.