Skip to content

Commit

Permalink
wip nikolalsvk#116 allow a custom content_for name
Browse files Browse the repository at this point in the history
  • Loading branch information
Doug committed May 15, 2020
1 parent 3fe5d71 commit 4bf10c1
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/views/render_async/_render_async.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<%= placeholder %>
</<%= html_element_name %>>

<% content_for :render_async do %>
<% content_for local_assigns.has_key?(:content_for_name) ? content_for_name : :render_async do %>
<%= javascript_tag html_options do %>
<% if RenderAsync.configuration.jquery %>
<%= render partial: 'render_async/request_jquery',
Expand Down
9 changes: 8 additions & 1 deletion lib/render_async/view_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def render_async(path, options = {}, &placeholder)
**request_options(options),
**error_handling_options(options),
retry_count: retry_count,
**polling_options(options)
**polling_options(options),
**content_for_options(options)
end

private
Expand All @@ -58,6 +59,12 @@ def polling_options(options)
toggle: options[:toggle] }
end

def content_for_options(options)
{
content_for_name: options[:content_for_name] || :render_async
}
end

private

def generate_container_id
Expand Down
68 changes: 56 additions & 12 deletions spec/render_async/view_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
error_message: nil,
error_event_name: nil,
retry_count: 0,
interval: nil
interval: nil,
content_for_name: :render_async
}
)

Expand Down Expand Up @@ -89,7 +90,8 @@
error_message: nil,
error_event_name: nil,
retry_count: 0,
interval: nil
interval: nil,
content_for_name: :render_async
}
)

Expand All @@ -116,7 +118,8 @@
error_message: nil,
error_event_name: nil,
retry_count: 0,
interval: nil
interval: nil,
content_for_name: :render_async
}
)

Expand All @@ -143,7 +146,8 @@
error_message: nil,
error_event_name: nil,
retry_count: 0,
interval: nil
interval: nil,
content_for_name: :render_async
}
)

Expand All @@ -170,7 +174,8 @@
error_message: nil,
error_event_name: nil,
retry_count: 0,
interval: nil
interval: nil,
content_for_name: :render_async
}
)

Expand All @@ -197,7 +202,8 @@
error_message: nil,
error_event_name: nil,
retry_count: 0,
interval: nil
interval: nil,
content_for_name: :render_async
}
)

Expand All @@ -224,7 +230,8 @@
error_message: nil,
error_event_name: nil,
retry_count: 0,
interval: nil
interval: nil,
content_for_name: :render_async
}
)

Expand All @@ -251,7 +258,8 @@
error_message: nil,
error_event_name: nil,
retry_count: 0,
interval: nil
interval: nil,
content_for_name: :render_async
}
)

Expand Down Expand Up @@ -284,7 +292,8 @@
error_message: nil,
error_event_name: nil,
retry_count: 0,
interval: nil
interval: nil,
content_for_name: :render_async
}
)

Expand All @@ -311,7 +320,8 @@
error_message: nil,
error_event_name: nil,
retry_count: 0,
interval: nil
interval: nil,
content_for_name: :render_async
}
)

Expand Down Expand Up @@ -343,7 +353,8 @@
error_message: nil,
error_event_name: nil,
retry_count: 5,
interval: nil
interval: nil,
content_for_name: :render_async
}
)

Expand Down Expand Up @@ -373,7 +384,8 @@
error_message: nil,
error_event_name: nil,
retry_count: 0,
interval: 5000
interval: 5000,
content_for_name: :render_async
}
)

Expand All @@ -383,5 +395,37 @@
)
end
end

context "content_for_name is given" do
it "renders render_async partial with proper parameters" do
expect(helper).to receive(:render).with(
"render_async/render_async",
{
html_element_name: "div",
container_id: /render_async_/,
container_class: nil,
path: "users",
html_options: {},
event_name: nil,
toggle: nil,
placeholder: nil,
method: 'GET',
data: nil,
headers: {},
error_message: nil,
error_event_name: nil,
retry_count: 0,
interval: nil,
content_for_name: :render_async_other_name
}
)

helper.render_async(
"users",
content_for_name: :render_async_other_name
)
end
end

end
end

0 comments on commit 4bf10c1

Please sign in to comment.