From 04c58135eec41d72f5554a87bb5dbb6b192e51de Mon Sep 17 00:00:00 2001 From: rgarcia Date: Sun, 25 Sep 2016 10:21:34 +0200 Subject: [PATCH] adds admin submit button helper --- app/helpers/admin_helper.rb | 4 ++++ spec/helpers/admin_helper_spec.rb | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 spec/helpers/admin_helper_spec.rb diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index 39ab74b96..f14269fb3 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -16,6 +16,10 @@ module AdminHelper Administrator.all.order('users.username asc').includes(:user).collect { |v| [ v.name, v.id ] } end + def admin_submit_action(resource) + resource.persisted? ? "edit" : "new" + end + private def namespace diff --git a/spec/helpers/admin_helper_spec.rb b/spec/helpers/admin_helper_spec.rb new file mode 100644 index 000000000..0239f1926 --- /dev/null +++ b/spec/helpers/admin_helper_spec.rb @@ -0,0 +1,19 @@ +require 'rails_helper' + +describe AdminHelper do + + describe "#admin_submit_action" do + + it "returns new when the the resource has not been persisted" do + poll = build(:poll) + expect(admin_submit_action(poll)).to eq("new") + end + + it "returns edit when the the resource has been persisted" do + poll = create(:poll) + expect(admin_submit_action(poll)).to eq("edit") + end + + end + +end \ No newline at end of file