On 11/22/2010 05:22 PM, [email protected] wrote:
> From: Ladislav Martincik<[email protected]>
>
> ---
>   src/app/helpers/providers_helper.rb       |   11 +++++++++++
>   src/app/views/providers/_providers.haml   |    3 +--
>   src/config/routes.rb                      |    2 +-
>   src/spec/helpers/providers_helper_spec.rb |   25 +++++++++++++++++++++++++
>   4 files changed, 38 insertions(+), 3 deletions(-)
>   create mode 100644 src/app/helpers/providers_helper.rb
>   create mode 100644 src/spec/helpers/providers_helper_spec.rb
>
> diff --git a/src/app/helpers/providers_helper.rb 
> b/src/app/helpers/providers_helper.rb
> new file mode 100644
> index 0000000..4da2a0b
> --- /dev/null
> +++ b/src/app/helpers/providers_helper.rb
> @@ -0,0 +1,11 @@
> +module ProvidersHelper
> +
> +  def edit_button(provider, action)
> +    if provider and ['show', 'accounts'].include? action
> +      link_to 'Edit', edit_provider_path(provider), :class =>  'button'
> +    else
> +      content_tag('a', 'Edit', :href =>  '#', :class =>  'button disabled')
> +    end
> +  end
> +
> +end
> diff --git a/src/app/views/providers/_providers.haml 
> b/src/app/views/providers/_providers.haml
> index b1a9bec..2719a7b 100644
> --- a/src/app/views/providers/_providers.haml
> +++ b/src/app/views/providers/_providers.haml
> @@ -7,7 +7,6 @@
>           - selected = 'selected' if @provider and (provider.id == 
> @provider.id)
>           %a{ :href =>  url_for(:controller =>  'providers', :action =>  
> 'show', :id =>  provider), :class =>  selected }
>             = provider.name
> -  - form_tag({:controller =>  'providers', :action =>  'edit', :id =>  
> @provider}, {:method =>  :post , :class =>  'buttononly'}) do
> -    = submit_tag t(:edit), :disabled =>  ('disabled' unless @provider and 
> ['show', 'accounts'].include? controller.action_name)
> +  = edit_button(@provider, controller.action_name)
>     - form_tag({:controller =>  'providers', :action =>  'new'}, {:method =>  
> :get , :class =>  'buttononly'}) do
>       %input{ :type =>  'submit', :value =>  t(:add), :disabled =>  
> ('disabled' unless @providers.length == 0) }
> diff --git a/src/config/routes.rb b/src/config/routes.rb
> index 8afbb6a..f59a2aa 100644
> --- a/src/config/routes.rb
> +++ b/src/config/routes.rb
> @@ -52,7 +52,7 @@ ActionController::Routing::Routes.draw do |map|
>
>     # Temporarily disable this route, provider stuff is not restful yet.
>     # Will be re-enabled in upcoming patch
> -  # map.resources :provider
> +  map.resources :providers
>
>     # Allow downloading Web Service WSDL as a file with an extension
>     # instead of a file named 'wsdl'
> diff --git a/src/spec/helpers/providers_helper_spec.rb 
> b/src/spec/helpers/providers_helper_spec.rb
> new file mode 100644
> index 0000000..ef7bc30
> --- /dev/null
> +++ b/src/spec/helpers/providers_helper_spec.rb
> @@ -0,0 +1,25 @@
> +require 'spec_helper'
> +
> +describe ProvidersHelper do
> +  include ProvidersHelper
> +
> +  context "edit_button() helper" do
> +
> +    it "formats link with path to edit action if rendered in show or 
> accounts action" do
> +      provider = Factory(:mock_provider)
> +
> +      edit_button(provider, 'show').should =~ /providers\/[0-9]*\/edit/
> +      edit_button(provider, 'accounts').should =~ /providers\/[0-9]*\/edit/
> +    end
> +
> +    it "formats blank link with no action and with disabled class if not in 
> show or accounts action" do
> +      provider = Factory(:mock_provider)
> +
> +      edit_button = edit_button(provider, 'index')
> +      edit_button.should =~ /href="#"/
> +      edit_button.should =~ /disabled/
> +    end
> +
> +  end
> +
> +end

Code looks good, only one problem - this patch breaks 2 provider's
cucumber tests (when you click on a provider in left panel, then
navigation menu is hidden, so probably some fix in config/navigation.rb).

_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to