From 4345e0415092c796e6c7b001be163b30582cc520 Mon Sep 17 00:00:00 2001 From: Juanito Fatas Date: Thu, 2 Oct 2014 18:31:32 +0800 Subject: [PATCH 1/5] Download gems via https. --- Gemfile | 2 +- Gemfile.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index c80ee36..b4e2a20 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,3 @@ -source "http://rubygems.org" +source "https://rubygems.org" gemspec diff --git a/Gemfile.lock b/Gemfile.lock index b7ae5bc..6546602 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -5,7 +5,7 @@ PATH rails (>= 3.2) GEM - remote: http://rubygems.org/ + remote: https://rubygems.org/ specs: actionmailer (4.0.5) actionpack (= 4.0.5) From 0d9970fff6734245aced6ff3f57475232b46a016 Mon Sep 17 00:00:00 2001 From: Juanito Fatas Date: Thu, 2 Oct 2014 18:31:46 +0800 Subject: [PATCH 2/5] Rename .markdown to .md --- README.markdown => README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README.markdown => README.md (100%) diff --git a/README.markdown b/README.md similarity index 100% rename from README.markdown rename to README.md From d7fce1ec79c1cb465e9512279077167f80bdd3a4 Mon Sep 17 00:00:00 2001 From: Juanito Fatas Date: Thu, 2 Oct 2014 18:32:13 +0800 Subject: [PATCH 3/5] Add more test cases to flash, minor markup tweaks. --- test/rails_utils_test.rb | 54 +++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/test/rails_utils_test.rb b/test/rails_utils_test.rb index db29edc..2dc0e8c 100644 --- a/test/rails_utils_test.rb +++ b/test/rails_utils_test.rb @@ -1,9 +1,9 @@ require 'test_helper' describe "RailsUtils::ActionViewExtensions" do - let(:controller) { ActionController::Base.new } - let(:request) { ActionDispatch::Request.new(flash: {}) } - let(:view) { ActionView::Base.new } + let(:controller) { ActionController::Base.new } + let(:request) { ActionDispatch::Request.new(flash: {}) } + let(:view) { ActionView::Base.new } before do controller.request = request @@ -37,14 +37,14 @@ describe "#page_action_class" do # action_name, expected [ - [ "index" , "index" ], - [ "show" , "show" ], - [ "new" , "new" ], - [ "create" , "new" ], - [ "edit" , "edit" ], - [ "update" , "edit" ], - [ "destroy", "destroy" ], - [ "custom" , "custom" ], + [ "index" , "index" ], + [ "show" , "show" ], + [ "new" , "new" ], + [ "create" , "new" ], + [ "edit" , "edit" ], + [ "update" , "edit" ], + [ "destroy", "destroy" ], + [ "custom" , "custom" ], ].each do |action_name, expected| describe "when ##{action_name}" do before { controller.stubs(:action_name).returns(action_name) } @@ -79,7 +79,7 @@ end describe 'when translation is missing' do - let(:action_name) { "random" } + let(:action_name) { "random" } let(:default_translation) { "#{controller_name.capitalize} #{action_name.capitalize}" } it "combines page_controller_class and page_action_class" do @@ -88,22 +88,22 @@ end describe 'when translation is avaiable' do - let(:action_name) { 'show' } + let(:action_name) { "show" } - before { I18n.backend.store_translations("en", {controller_name.to_sym => {action_name.to_sym => {title: "An awesome title"}}}) } + before { I18n.backend.store_translations("en", { controller_name.to_sym => { action_name.to_sym => { title: "An awesome title" } }}) } - it 'translates page title' do - view.page_title.must_equal 'An awesome title' + it "translates page title" do + view.page_title.must_equal "An awesome title" end end - describe 'when translation is avaiable + interpolations' do - let(:action_name) { 'show' } + describe "when translation is avaiable + interpolations" do + let(:action_name) { "show" } - before { I18n.backend.store_translations("en", {controller_name.to_sym => {action_name.to_sym => {title: "An awesome title, %{name}"}}}) } + before { I18n.backend.store_translations("en", { controller_name.to_sym => { action_name.to_sym => { title: "An awesome title, %{name}" } }}) } - it 'translates page title' do - view.page_title(name: 'bro').must_equal 'An awesome title, bro' + it "translates page title" do + view.page_title(name: "bro").must_equal "An awesome title, bro" end end end @@ -118,7 +118,7 @@ end describe "when controller name and action name are standard" do - let(:action_name) { "custom" } + let(:action_name) { "custom" } it "invokes application" do view.javascript_initialization.must_match "Dummy.init();" @@ -131,7 +131,7 @@ end describe "when action name is create" do - let(:action_name) { "create" } + let(:action_name) { "create" } it "replaces create with new" do view.javascript_initialization.must_match "Dummy.#{controller_name}.init_new();" @@ -139,7 +139,7 @@ end describe "when action name is update" do - let(:action_name) { "update" } + let(:action_name) { "update" } it "replaces update with create" do view.javascript_initialization.must_match "Dummy.#{controller_name}.init_edit();" @@ -157,9 +157,11 @@ def set_flash(key, message) # alert-error is for Bootstrap 2.3.2 [ [ :success , /alert alert-success/ , "flash is success" ], + [ "success", /alert alert-success/ , "flash is success" ], [ :notice , /alert alert-info/ , "flash is notice" ], [ "notice" , /alert alert-info/ , "flash is notice" ], [ :error , /alert alert-danger alert-error/ , "flash is error" ], + [ "error" , /alert alert-danger alert-error/ , "flash is error" ], [ :alert , /alert alert-danger alert-error/ , "flash is alert" ], [ "alert" , /alert alert-danger alert-error/ , "flash is alert" ], [ :custom , /alert alert-custom/ , "flash is custom" ], @@ -180,12 +182,12 @@ def set_flash(key, message) describe "when bootstrap is present" do it "can fade in and out" do - set_flash :alert , "not important" + set_flash :alert, "not important" view.flash_messages.must_match /fade in/ end it "can be dismissed" do - set_flash :alert , "not important" + set_flash :alert, "not important" view.flash_messages.must_match /data-dismiss=.*alert/ end end From 2087247ae252a1dc55e024e7d3348cd741d130e4 Mon Sep 17 00:00:00 2001 From: Juanito Fatas Date: Thu, 2 Oct 2014 18:32:27 +0800 Subject: [PATCH 4/5] Simplify flash_messages --- lib/rails_utils.rb | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/rails_utils.rb b/lib/rails_utils.rb index 53279dd..91dbbcb 100644 --- a/lib/rails_utils.rb +++ b/lib/rails_utils.rb @@ -33,24 +33,18 @@ def javascript_initialization JS end - def flash_messages - html = "" - flash.each do |key, message| - html << - content_tag(:div, class: "#{flash_class(key.to_sym)} fade in") do - content = "" - content << content_tag(:button, "x", type: "button", class: "close", "data-dismiss" => "alert") - content << message - content.html_safe - end - end - html.html_safe + def flash_messages(options = {}) + flash.collect do |key, message| + next if message.blank? + + content_tag(:div, content_tag(:button, "x", type: "button", class: "close", "data-dismiss" => "alert") + message, class: "#{flash_class(key)} fade in #{options[:class]}") + end.join("\n").html_safe end private def flash_class(key) - case key + case key.to_sym when :success "alert alert-success" when :notice From 9098aa92c95a3b60a3512c2fa9a3fcbda6522e58 Mon Sep 17 00:00:00 2001 From: Juanito Fatas Date: Thu, 2 Oct 2014 18:32:41 +0800 Subject: [PATCH 5/5] Enable testing ruby 2.2 and latest 2.1 on Travis. --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d1479f5..ba7c27a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,8 @@ language: ruby rvm: - 1.9.3 - 2.0.0 - - 2.1.0 + - 2.1 + - 2.2 branches: only: