Skip to content

Commit

Permalink
Merge pull request #72 from taketo1113/test-keywordargs
Browse files Browse the repository at this point in the history
Add test when use `call` with keyword args
  • Loading branch information
apotonick authored Feb 3, 2023
2 parents e8deb29 + f7a9c66 commit b4c491f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion test/dummy/app/cells/song_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ def show
def with_escaped
render
end

def with_title(with_title: '')
"<h1>#{with_title}</h1>"
end
# include ActionView::Helpers::AssetUrlHelper
# include Sprockets::Rails::Helper

# self.assets_prefix = Rails.application.config.assets.prefix
# self.assets_environment = Rails.application.assets
# self.digest_assets = Rails.application.config.assets[:digest]
end
end
4 changes: 4 additions & 0 deletions test/dummy/app/controllers/musician_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def view_with_cell_with_call
render inline: %{<%= cell("view_extensions_test/song", "A Tale That Wasn't Right").call %>}
end

def view_with_cell_with_call_keyword_args
render inline: %{<%= cell("view_extensions_test/song", "A Tale That Wasn't Right").call(:with_title, with_title: 'test') %>}
end

def view_with_collection_without_call
render inline: %{<%= cell("view_extensions_test/song", collection: ["A Tale That Wasn't Right"]) %>}
end
Expand Down
1 change: 1 addition & 0 deletions test/dummy/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
get :view_with_concept_without_call
get :view_with_concept_with_call
get :view_with_cell_with_call
get :view_with_cell_with_call_keyword_args
get :view_with_collection_without_call
get :action_with_concept_with_call
get :action_with_cell_with_call
Expand Down
13 changes: 13 additions & 0 deletions test/dummy/test/rails_extensions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@ class Cell < Cell::Concept
def show
"<b>#{model}</b>"
end

def with_title(with_title: '')
"<h1>#{with_title}</h1><b>#{model}</b>"
end
end

class SongCell < ::Cell::ViewModel
def show
"<b>#{model}</b>"
end

def with_title(with_title: '')
"<h1>#{with_title}</h1><b>#{model}</b>"
end
end


Expand Down Expand Up @@ -42,6 +50,11 @@ def show
assert_equal "<b>A Tale That Wasn't Right</b>", @response.body
end

test "cell(..) with #call keyword args" do
get :view_with_cell_with_call_keyword_args
assert_equal "<h1>test</h1><b>A Tale That Wasn't Right</b>", @response.body
end

# Controller#concept
test "Controller#concept(..).call" do
get :action_with_concept_with_call
Expand Down
4 changes: 4 additions & 0 deletions test/dummy/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def view_with_cell_with_call
render inline: %{<%= cell("view_extensions_test/song", "A Tale That Wasn't Right").call %>}
end

def view_with_cell_with_call_keyword_args
render inline: %{<%= cell("view_extensions_test/song", "A Tale That Wasn't Right").call(:with_title, with_title: 'test') %>}
end

def view_with_collection_without_call
render inline: %{<%= cell("view_extensions_test/song", collection: ["A Tale That Wasn't Right"]) %>}
end
Expand Down

0 comments on commit b4c491f

Please sign in to comment.