diff --git a/app/controllers/spree/admin/suppliers_controller.rb b/app/controllers/spree/admin/suppliers_controller.rb index 61debf2b04..ae02ca9384 100644 --- a/app/controllers/spree/admin/suppliers_controller.rb +++ b/app/controllers/spree/admin/suppliers_controller.rb @@ -5,12 +5,12 @@ module Spree private def load_data - @countries = Country.order(:name) + @countries = Country.order(:name) end def collection - super.order(:name) + super.order(:name) end end end -end \ No newline at end of file +end diff --git a/app/views/spree/admin/distributors/_form.html.erb b/app/views/spree/admin/distributors/_form.html.erb deleted file mode 100644 index d7db0cbbdb..0000000000 --- a/app/views/spree/admin/distributors/_form.html.erb +++ /dev/null @@ -1,67 +0,0 @@ -
| Name: | -<%= f.text_field :name %> | -
| Description: | -<%= f.text_field :description %> | -
| Contact: | -<%= f.text_field :contact %> | -
| Phone: | -<%= f.text_field :phone %> | -
| Email: | -<%= f.text_field :email %> | -
| Address: | -<%= f.text_field :pickup_address %> | -
| City: | -<%= f.text_field :city %> | -
| Post code: | -<%= f.text_field :post_code %> | -
| Country: | -<%= f.collection_select(:country_id, @countries, :id, :name, :include_blank => true) %> | -
| State: | -<%= f.collection_select(:state_id, @distributor.country.states, :id, :name, :include_blank => true) %> | -
| Pickup times: | -<%= f.text_field :pickup_times %> | -
| URL: | -<%= f.text_field :url %> | -
| ABN: | -<%= f.text_field :abn %> | -
| ACN: | -<%= f.text_field :acn %> | -
| Name | -- <%= @distributor.name %> - | -
|---|---|
| Description | -- <%= @distributor.description %> - | -
| Contact person | -- <%= @distributor.contact %> - | -
| Phone number | -- <%= @distributor.phone %> - | -
| - <%= @distributor.email %> - | -Pickup address | -- <%= @distributor.pickup_address %> - | - -Pickup city | -- <%= @distributor.city %> - | - -Pickup post code | -- <%= @distributor.post_code %> - | - -Pickup country | -- <%= @distributor.country.name if @distributor.country %> - | - -Pickup state | -- <%= @distributor.state.name if @distributor.state %> - | - - -Pickup times | -- <%= @distributor.pickup_times %> - | - - -ABN | -- <%= @distributor.abn %> - | - - -ACN | -- <%= @distributor.acn %> - | - - -URL | -- <%= @distributor.url %> - | - -
- <%= link_to :Edit, spree.edit_admin_distributor_path(@distributor), :class => 'edit_distributor' %> <%= t(:or) %> - <%= link_to t(:back), spree.admin_distributors_path %> -
\ No newline at end of file diff --git a/app/views/spree/admin/distributors/show.html.haml b/app/views/spree/admin/distributors/show.html.haml new file mode 100644 index 0000000000..9ba1aa4326 --- /dev/null +++ b/app/views/spree/admin/distributors/show.html.haml @@ -0,0 +1,36 @@ +%h1 Distributor +%table + %tr + %th Name: + %td= @distributor.name + %tr + %th Description: + %td= @distributor.description + %tr + %th Contact person: + %td= @distributor.contact + %tr + %th Phone number: + %td= @distributor.phone + %tr + %th Email: + %td= @distributor.email + %tr + %th Pickup address: + %td= render 'spree/admin/shared/address', :address => @distributor.pickup_address + %tr + %th Pickup times: + %td= @distributor.pickup_times + %tr + %th ABN: + %td= @distributor.abn + %tr + %th ACN: + %td= @distributor.acn + %tr + %th URL: + %td= @distributor.url +%p + = link_to :Edit, spree.edit_admin_distributor_path(@distributor), :class => 'edit_distributor' + = t(:or) + = link_to t(:back), spree.admin_distributors_path diff --git a/app/views/spree/admin/shared/_address.html.haml b/app/views/spree/admin/shared/_address.html.haml new file mode 100644 index 0000000000..976a85adc8 --- /dev/null +++ b/app/views/spree/admin/shared/_address.html.haml @@ -0,0 +1,4 @@ += address.address1 += ", #{address.address2}" unless address.address2.blank? +%br/ += [address.city, address.state_text, address.zipcode, address.country.name].compact.join ', ' diff --git a/app/views/spree/admin/shared/_address_form.html.haml b/app/views/spree/admin/shared/_address_form.html.haml new file mode 100644 index 0000000000..d03142b161 --- /dev/null +++ b/app/views/spree/admin/shared/_address_form.html.haml @@ -0,0 +1,18 @@ +%tr{"data-hook" => "address1"} + %td Address: + %td= form.text_field :address1 +%tr{"data-hook" => "address2"} + %td Address (cont.): + %td= form.text_field :address2 +%tr{"data-hook" => "city"} + %td City: + %td= form.text_field :city +%tr{"data-hook" => "zipcode"} + %td Postcode: + %td= form.text_field :zipcode +%tr{"data-hook" => "country"} + %td Country: + %td= form.collection_select(:country_id, available_countries, :id, :name) +%tr{"data-hook" => "state"} + %td State: + %td= form.collection_select(:state_id, form.object.country.states, :id, :name) diff --git a/app/views/spree/admin/suppliers/_form.html.haml b/app/views/spree/admin/suppliers/_form.html.haml index 982ec653e1..c1e066d2d0 100644 --- a/app/views/spree/admin/suppliers/_form.html.haml +++ b/app/views/spree/admin/suppliers/_form.html.haml @@ -5,21 +5,8 @@ %tr{'data-hook' => "description"} %td Description: %td= f.text_field :description - %tr{'data-hook' => "address"} - %td Address: - %td= f.text_field :address - %tr{'data-hook' => "city"} - %td City: - %td= f.text_field :city - %tr{'data-hook' => "post_code"} - %td Post Code: - %td= f.text_field :postcode - %tr{'data-hook' => "country"} - %td Country: - %td= f.collection_select(:country_id, @countries, :id, :name, :include_blank => true) - %tr{'data-hook' => "state"} - %td State: - %td= f.collection_select(:state_id, @supplier.country.states, :id, :name, :include_blank => true) + = f.fields_for :address do |address_form| + = render 'spree/admin/shared/address_form', :form => address_form %tr{'data-hook' => "email"} %td Email: %td= f.text_field :email @@ -28,4 +15,4 @@ %td= f.text_field :website %tr{'data-hook' => "twitter"} %td Twitter: - %td= f.text_field :twitter \ No newline at end of file + %td= f.text_field :twitter diff --git a/app/views/spree/admin/suppliers/show.html.haml b/app/views/spree/admin/suppliers/show.html.haml index 1f741568f5..3c939ad2cd 100644 --- a/app/views/spree/admin/suppliers/show.html.haml +++ b/app/views/spree/admin/suppliers/show.html.haml @@ -1,34 +1,22 @@ %h1 Supplier %table %tr - %th Name + %th Name: %td= @supplier.name %tr - %th Description + %th Description: %td= @supplier.description %tr - %th Address - %td= @supplier.address + %th Address: + %td= render 'spree/admin/shared/address', :address => @supplier.address %tr - %th City: - %td= @supplier.city - %tr - %th Post Code: - %td= @supplier.postcode - %tr - %th Country: - %td= @supplier.country.name if @supplier.country - %tr - %th State: - %td= @supplier.state.name if @supplier.state - %tr - %th Email + %th Email: %td= @supplier.email %tr - %th Website + %th Website: %td= @supplier.website %tr - %th Twitter + %th Twitter: %td= @supplier.twitter %p = link_to :Edit, spree.edit_admin_supplier_path(@supplier), :class => 'edit_supplier' diff --git a/spec/requests/admin/distributors_spec.rb b/spec/requests/admin/distributors_spec.rb index 0d85d277a5..b9fc1d06b6 100644 --- a/spec/requests/admin/distributors_spec.rb +++ b/spec/requests/admin/distributors_spec.rb @@ -7,11 +7,9 @@ feature %q{ include AuthenticationWorkflow include WebHelper - background do - end - context "Given I am setting up distributors" do - scenario "I should be able to create a new distributor" do + context "setting up distributors" do + scenario "creating a new distributor" do login_to_admin_section click_link 'Distributors' @@ -21,11 +19,13 @@ feature %q{ fill_in 'distributor_description', :with => 'Connecting farmers and eaters' fill_in 'distributor_contact', :with => 'Kirsten or Ren' fill_in 'distributor_phone', :with => '0413 897 321' - fill_in 'distributor_pickup_address', :with => '35 Ballantyne St' - fill_in 'distributor_city', :with => 'Thornbury' - fill_in 'distributor_post_code', :with => '3072' - select('Australia', :from => 'distributor_country_id') - select('Victoria', :from => 'distributor_state_id') + + fill_in 'distributor_pickup_address_attributes_address1', :with => '35 Ballantyne St' + fill_in 'distributor_pickup_address_attributes_city', :with => 'Thornbury' + fill_in 'distributor_pickup_address_attributes_zipcode', :with => '3072' + select('Australia', :from => 'distributor_pickup_address_attributes_country_id') + select('Victoria', :from => 'distributor_pickup_address_attributes_state_id') + fill_in 'distributor_pickup_times', :with => 'Thursday, 22nd Feb, 6 - 9 PM. Friday, 23nd Feb, 6 - 9 PM' fill_in 'distributor_email', :with => 'info@eaterprises.com.au' fill_in 'distributor_url', :with => 'http://eaterprises.com.au' diff --git a/spec/requests/admin/suppliers_spec.rb b/spec/requests/admin/suppliers_spec.rb index 0cb5ecc137..3c7b4deea0 100644 --- a/spec/requests/admin/suppliers_spec.rb +++ b/spec/requests/admin/suppliers_spec.rb @@ -10,27 +10,29 @@ feature %q{ background do end - context "Given I am setting up suppliers" do - scenario "I should be able to create a new supplier" do + context "setting up suppliers" do + scenario "creating a new supplier" do login_to_admin_section click_link 'Suppliers' click_link 'New Supplier' - fill_in 'supplier_name', :with => 'David arnold' + fill_in 'supplier_name', :with => 'David Arnold' fill_in 'supplier_description', :with => 'A farmer with a difference' - fill_in 'supplier_address', :with => '35 Byron Ave' - fill_in 'supplier_city', :with => 'Ararat' - fill_in 'supplier_postcode', :with => '1112' - select('Australia', :from => 'supplier_country_id') - select('Victoria', :from => 'supplier_state_id') + + fill_in 'supplier_address_attributes_address1', :with => '35 Byron Ave' + fill_in 'supplier_address_attributes_city', :with => 'Ararat' + fill_in 'supplier_address_attributes_zipcode', :with => '1112' + select('Australia', :from => 'supplier_address_attributes_country_id') + select('Victoria', :from => 'supplier_address_attributes_state_id') + fill_in 'supplier_email', :with => 'david@here.com' fill_in 'supplier_website', :with => 'http://somewhere.com' fill_in 'supplier_twitter', :with => 'davida' click_button 'Create' - flash_message.should == 'Supplier "David arnold" has been successfully created!' + flash_message.should == 'Supplier "David Arnold" has been successfully created!' end end end