Permalink
Browse files

Merge pull request #41 from jamesarosen/message_cleanup

Message cleanup
  • Loading branch information...
2 parents 4da9887 + 5757c81 commit 01a64fb9a013181eab9b36dd714291a856b7b2c7 @jamesarosen jamesarosen committed Mar 23, 2013
View
2 Gemfile
@@ -1,3 +1,3 @@
-source 'https://bundler-api.herokuapp.com'
+source 'https://rubygems.org'
gemspec
View
2 app/controllers/arturo/features_controller.rb
@@ -40,7 +40,7 @@ def update_all
elsif feature.update_attributes(attributes)
updated_count += 1
else
- errors << t('arturo.features.flash.error_updating', :id => id)
+ errors << t('arturo.features.flash.error_updating', :id => id, :errors => feature.errors.full_messages.to_sentence)
end
end
if errors.any?
View
17 app/helpers/arturo/features_helper.rb
@@ -1,10 +1,27 @@
+require 'action_view'
require 'action_view/helpers/tag_helper'
require 'action_view/helpers/form_tag_helper'
module Arturo
module FeaturesHelper
include ActionView::Helpers::TagHelper
+ def arturo_flash_messages(flash = self.flash)
+ [ :success, :notice, :error ].inject(''.html_safe) do |output, status|
+ [* flash[status] ].each do |messages|
+ output += arturo_flash_message(status, messages)
+ end
+ output
+ end
+ end
+
+ def arturo_flash_message(status, message)
+ content_tag(:div, :class => "alert alert-#{status} alert-arturo") do
+ close = content_tag(:a, '&times;'.html_safe, :href => '#', :class => 'close', 'data-dismiss' => 'alert')
+ content_tag(:span, message) + close
+ end
+ end
+
def deployment_percentage_range_and_output_tags(name, value, options = {})
id = sanitize_to_id(name)
options = {
View
3 app/views/arturo/features/edit.html.erb
@@ -1,2 +1,5 @@
<h2><%= t('.title', :name => @feature.name) %></h2>
+
+<%= arturo_flash_messages %>
+
<%= render :partial => 'form', :locals => { :feature => @feature, :legend => t('.legend', :name => @feature.name) } %>
View
3 app/views/arturo/features/forbidden.html.erb
@@ -1,2 +1,5 @@
<h2><%= t('.title') %></h2>
+
+<%= arturo_flash_messages %>
+
<p><%= t('.text') %></p>
View
3 app/views/arturo/features/index.html.erb
@@ -1,4 +1,7 @@
<h2><%= t('.title') %></h2>
+
+<%= arturo_flash_messages %>
+
<%= form_tag(arturo_engine.features_path, :method => 'put', 'data-update-path' => arturo_engine.feature_path(:id => ':id'), :remote => true) do %>
<fieldset>
<legend><%= t('.title') %></legend>
View
3 app/views/arturo/features/new.html.erb
@@ -1,2 +1,5 @@
<h2><%= t('.title') %></h2>
+
+<%= arturo_flash_messages %>
+
<%= render :partial => 'form', :locals => { :feature => @feature, :legend => t('.legend') } %>
View
3 app/views/arturo/features/show.html.erb
@@ -1,2 +1,5 @@
<h2><%= t('.title', :name => @feature.name) %></h2>
+
+<%= arturo_flash_messages %>
+
<p>Deployment percentage: <%= @feature.deployment_percentage %></p>
View
2 config/locales/en.yml
@@ -35,6 +35,6 @@ en:
created: "Created %{name}"
error_creating: "Sorry, there was an error creating the feature."
updated: "Updated %{name}"
- error_updating: "Sorry, there was an error updating %{name}"
+ error_updating: "Could not update feature #%{id}: %{errors}."
removed: "Removed %{name}"
error_removing: "Sorry, there was an error removing %{name}"
View
2 gemfiles/rails3_0.gemfile
@@ -1,6 +1,6 @@
# This file was generated by Appraisal
-source "https://bundler-api.herokuapp.com"
+source "https://rubygems.org"
gem "rails", "~> 3.0.20"
View
2 gemfiles/rails3_1.gemfile
@@ -1,6 +1,6 @@
# This file was generated by Appraisal
-source "https://bundler-api.herokuapp.com"
+source "https://rubygems.org"
gem "rails", "~> 3.1.11"
View
2 gemfiles/rails3_2.gemfile
@@ -1,6 +1,6 @@
# This file was generated by Appraisal
-source "https://bundler-api.herokuapp.com"
+source "https://rubygems.org"
gem "rails", "~> 3.2.8"
View
2 gemfiles/rails4_0.gemfile
@@ -1,6 +1,6 @@
# This file was generated by Appraisal
-source "https://bundler-api.herokuapp.com"
+source "https://rubygems.org"
gem "rails", "4.0.0.beta1"
View
23 test/dummy_app/test/unit/features_helper_test.rb
@@ -4,6 +4,7 @@
class ArturoFeaturesHelperTest < ActiveSupport::TestCase
include ActionView::Helpers::TagHelper
+ include ActionDispatch::Assertions::SelectorAssertions
include Arturo::FeaturesHelper
attr_accessor :output_buffer
@@ -15,11 +16,33 @@ def bad_feature
end
end
+ def assert_select_in(html, selector, equality=nil, message=nil, &block)
+ assert_select(HTML::Document.new(html).root, selector, equality, &block)
+ rescue ArgumentError => e
+ if e.message =~ /assertion message must be String or Proc/
+ raise Test::Unit::AssertionFailedError.new("Expected #{selector.inspect} to match, but it didn't")
+ else
+ raise
+ end
+ end
+
def test_error_messages_for
expected = "<ul class=\"errors\"><li class=\"error\">must be less than or equal to 100</li></ul>"
actual = error_messages_for(bad_feature, :deployment_percentage)
assert_equal expected, actual
assert actual.html_safe?
end
+
+ def test_flash_messages
+ html = arturo_flash_messages({
+ :notice => 'foo',
+ :error => [ 'bar', 'baz' ]
+ })
+ assert_select_in html, '.alert.alert-arturo .close[data-dismiss="alert"]', :count => 3
+ assert_select_in html, '.alert-notice', /^foo/
+ assert_select_in html, '.alert-error', /^bar/
+ assert_select_in html, '.alert-error', /^baz/
+ end
+
end

0 comments on commit 01a64fb

Please sign in to comment.