diff options
| author | jpl | 2016-10-18 12:22:38 +0200 |
|---|---|---|
| committer | jpl | 2016-10-18 12:22:38 +0200 |
| commit | a9aa01e2271fda736e13d1a10bd62f45e1508330 (patch) | |
| tree | 2ffa792d45b91f514706b3aeaed5d281d5c88d77 | |
| parent | f282672d581a826411271dc37fd173bf49f30f76 (diff) | |
| download | chouette-core-a9aa01e2271fda736e13d1a10bd62f45e1508330.tar.bz2 | |
update tablebuilder with path new helpers
| -rw-r--r-- | app/helpers/path_builder_helper.rb | 11 | ||||
| -rw-r--r-- | app/helpers/refobjects_helper.rb | 31 | ||||
| -rw-r--r-- | app/views/companies/_companies.html.slim | 2 | ||||
| -rw-r--r-- | spec/views/companies/index.html.erb_spec.rb | 12 |
4 files changed, 37 insertions, 19 deletions
diff --git a/app/helpers/path_builder_helper.rb b/app/helpers/path_builder_helper.rb new file mode 100644 index 000000000..482cb91f0 --- /dev/null +++ b/app/helpers/path_builder_helper.rb @@ -0,0 +1,11 @@ +module PathBuilderHelper + + # Companies + def company_path(company) + line_referential_company_path(company.line_referential_id, company) + end + def edit_company_path(company) + edit_line_referential_company_path(company.line_referential_id, company) + end + +end diff --git a/app/helpers/refobjects_helper.rb b/app/helpers/refobjects_helper.rb index f7ebb65ea..aac40b944 100644 --- a/app/helpers/refobjects_helper.rb +++ b/app/helpers/refobjects_helper.rb @@ -5,26 +5,31 @@ module RefobjectsHelper head = content_tag :thead do content_tag :tr do - columns.each do |col| - concat content_tag :th, col.to_s.titleize - end - concat content_tag :th, "Actions" if actions.any? + attributes_head = columns.collect do |col| + content_tag :th, col.to_s.titleize + end.join.html_safe + links_head = content_tag :th, "Actions" if actions.any? + attributes_head + links_head end end body = content_tag :tbody do collection.collect { |item| content_tag :tr do - columns.collect { |col| - concat content_tag(:td, item.try(col)) - }.to_s.html_safe + attributes = columns.collect { |col| + content_tag(:td, item.try(col)) + }.join.html_safe + # Build links - concat content_tag :td, autolinks_builder(item, actions, :xs) if actions.any? + links = content_tag :td, autolinks_builder(item, actions, :xs), class: 'text-center' if actions.any? + + attributes + links end - }.join().html_safe + }.join.html_safe end - content_tag :table, head.concat(body), class: cls + # content_tag :table, head + body, class: cls + content_tag :table, "pouet" end def autolinks_builder(item, actions, cls) @@ -32,17 +37,17 @@ module RefobjectsHelper actions.each do |action| if action == "show" - showlink = link_to({controller: params[:controller], action: action, id: item}, class: 'btn btn-default') do + showlink = link_to(company_path(item), class: 'btn btn-default') do content_tag :span, "", class: 'fa fa-eye' end link << showlink elsif action == "edit" - editlink = link_to({controller: params[:controller], action: action, id: item.id}, class: 'btn btn-default') do + editlink = link_to(edit_company_path(item), class: 'btn btn-default') do content_tag :span, "", class: 'fa fa-pencil' end link << editlink elsif action == "delete" - deletelink = link_to({controller: params[:controller], action: "show", id: item.id}, method: :delete, data: { confirm: 'Are you sure?'}, class: 'btn btn-default') do + deletelink = link_to(company_path(item), method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-default') do content_tag :span, "", class: 'fa fa-trash-o' end link << deletelink diff --git a/app/views/companies/_companies.html.slim b/app/views/companies/_companies.html.slim index 028a21af4..4f89e8ede 100644 --- a/app/views/companies/_companies.html.slim +++ b/app/views/companies/_companies.html.slim @@ -5,7 +5,7 @@ .companies.paginated_content style="margin-top:20px;" = table_builder @decoratedcompanies, [:name, :edited_at, :published_at, :validity_period, :linecount, :transporter, :status], - ["show"], + ["show", "delete"], 'table table-bordered' .pagination diff --git a/spec/views/companies/index.html.erb_spec.rb b/spec/views/companies/index.html.erb_spec.rb index 6f244064d..43981ac87 100644 --- a/spec/views/companies/index.html.erb_spec.rb +++ b/spec/views/companies/index.html.erb_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe "/companies/index", :type => :view do +RSpec.describe "/companies/index", :type => :view do let!(:line_referential) { assign :line_referential, create(:line_referential) } let!(:companies) { assign :companies, CompanyDecorator.decorate_collection(Array.new(2) { create(:company, line_referential: line_referential) }.paginate) } @@ -9,14 +9,16 @@ describe "/companies/index", :type => :view do # Fixme #1795 # it "should render a show link for each group" do # render + # puts rendered + # # companies.each do |company| # expect(rendered).to have_selector("a[href='#{view.line_referential_company_path(line_referential, company)}']") # end # end - # it "should render a link to create a new group" do - # render - # expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{new_line_referential_company_path(line_referential)}']") - # end + it "should render a link to create a new group" do + render + expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{new_line_referential_company_path(line_referential)}']") + end end |
