Skip to content

Commit

Permalink
Begin r_c refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Neeraj Singh authored and schof committed Feb 21, 2011
1 parent 54e568c commit aa236a7
Show file tree
Hide file tree
Showing 29 changed files with 255 additions and 128 deletions.
46 changes: 43 additions & 3 deletions core/app/controllers/admin/adjustments_controller.rb
@@ -1,9 +1,49 @@
class Admin::AdjustmentsController < Admin::BaseController

before_filter :load_order, :only => [:index, :new, :create, :edit, :update]
before_filter :load_adjustment, :only => [:edit, :update]

resource_controller
belongs_to :order

update.wants.html { redirect_to collection_url }
create.wants.html { redirect_to collection_url }
destroy.success.wants.js { @order.reload && render_js_for_destroy }

def index
render
end

def new
@adjustment = @order.adjustments.build
end

def edit
render
end

def update
if @adjustment.update_attributes(params[:adjustment])
redirect_to admin_order_adjustments_path(@order), :notice => "Successfully updated!"
else
render :action => :edit
end
end

def create
@adjustment = @order.adjustments.create(params[:adjustment])
if @adjustment.errors.any?
render :action => :new
else
redirect_to admin_order_adjustments_path(@order), :notice => "Successfully created!"
end
end

private

def load_order
@order = Order.find_by_number(params[:order_id])
end

def load_adjustment
@adjustment = @order.adjustments.find(params[:id])
end

end
10 changes: 8 additions & 2 deletions core/app/controllers/admin/configurations_controller.rb
@@ -1,4 +1,5 @@
class Admin::ConfigurationsController < Admin::BaseController

before_filter :initialize_extension_links, :only => :index

class << self
Expand All @@ -17,8 +18,13 @@ def add_link(text, path, description)

def initialize_extension_links
@extension_links = [
{:link => admin_shipping_methods_path, :link_text => t("shipping_methods"), :description => t("shipping_methods_description")},
{:link => admin_shipping_categories_path, :link_text => t("shipping_categories"), :description => t("shipping_categories_description")},
{:link => admin_shipping_methods_path,
:link_text => t("shipping_methods"),
:description => t("shipping_methods_description")},

{:link => admin_shipping_categories_path,
:link_text => t("shipping_categories"),
:description => t("shipping_categories_description")},
] + @@extension_links
end

Expand Down
32 changes: 17 additions & 15 deletions core/app/controllers/admin/users_controller.rb
@@ -1,6 +1,9 @@
class Admin::UsersController < Admin::BaseController
resource_controller
before_filter :check_json_authenticity, :only => :index

#FIXME why is this needed?
#before_filter :check_json_authenticity, :only => :index

before_filter :load_roles, :only => [:edit, :new, :update, :create]

create.after :save_user_roles
Expand All @@ -22,27 +25,26 @@ def json_data
when 'basic'
collection.map {|u| {'id' => u.id, 'name' => u.email}}.to_json
else
collection.to_json(:include =>
{:bill_address => {:include => [:state, :country]},
:ship_address => {:include => [:state, :country]}})
collection.to_json( :only => [:email],
:include => { :bill_address => {:include => [:state, :country]},
:ship_address => {:include => [:state, :country]}})
end
end

def collection
return @collection if @collection.present?
unless request.xhr?
if request.xhr?
raise 'boom write test for this case if it is a valid case FIXME'
@collection = User.includes(:bill_address => [:state, :country], :ship_address => [:state, :country])
@collection = @collection.where("users.email like :search
OR addresses.firstname like :search
OR addresses.lastname like :search
OR ship_addresses_users.firstname like :search
OR ship_addresses_users.lastname like :search",{:search => "#{params[:q].strip}%"})
@collection = @collection.limit(params[:limit] || 100)
else
@search = User.search(params[:search])

@collection = @search.paginate(:per_page => Spree::Config[:admin_products_per_page], :page => params[:page])

#scope = scope.conditions "lower(email) = ?", @filter.email.downcase unless @filter.email.blank?
else
@collection = User.includes(:bill_address => [:state, :country], :ship_address => [:state, :country]).where("users.email like :search
OR addresses.firstname like :search
OR addresses.lastname like :search
OR ship_addresses_users.firstname like :search
OR ship_addresses_users.lastname like :search",
{:search => "#{params[:q].strip}%"}).limit(params[:limit] || 100)
end
end

Expand Down
4 changes: 4 additions & 0 deletions core/app/controllers/locale_controller.rb
@@ -1,14 +1,18 @@
class LocaleController < Spree::BaseController

def set
if request.referer && request.referer.starts_with?("http://" + request.host)
session["user_return_to"] = request.referer
end

if params[:locale] && I18n.available_locales.include?(params[:locale].to_sym)
session[:locale] = I18n.locale = params[:locale].to_sym
flash.notice = t(:locale_changed)
else
flash[:error] = t(:locale_not_changed)
end

redirect_back_or_default(root_path)
end

end
6 changes: 3 additions & 3 deletions core/app/controllers/orders_controller.rb
Expand Up @@ -34,9 +34,9 @@ def edit
def populate
@order = current_order(true)

params[:products].each do |product_id,variant_id|
quantity = params[:quantity].to_i if !params[:quantity].is_a?(Hash)
quantity = params[:quantity][variant_id].to_i if params[:quantity].is_a?(Hash)
params[:products].each do |product_id, variant_id|
quantity = params[:quantity].is_a?(Hash) ? params[:quantity][variant_id] : params[:quantity]
quantity = quantity.to_i
@order.add_variant(Variant.find(variant_id), quantity) if quantity > 0
end if params[:products]

Expand Down
30 changes: 10 additions & 20 deletions core/app/controllers/products_controller.rb
@@ -1,37 +1,27 @@
class ProductsController < Spree::BaseController
HTTP_REFERER_REGEXP = /^https?:\/\/[^\/]+\/t\/([a-z0-9\-\/]+)$/

#prepend_before_filter :reject_unknown_object, :only => [:show]
before_filter :load_data, :only => :show
HTTP_REFERER_REGEXP = /^https?:\/\/[^\/]+\/t\/([a-z0-9\-\/]+)$/

resource_controller
helper :taxons
actions :show, :index

private

def load_data
load_object

@variants = Variant.active.find_all_by_product_id(@product.id,
:include => [:option_values, :images])
@product_properties = ProductProperty.find_all_by_product_id(@product.id,
:include => [:property])
def show
@product = Product.where(:permalink => params[:id]).limit(1).first
@variants = Variant.active.find_all_by_product_id(@product.id, :include => [:option_values, :images])
@product_properties = ProductProperty.find_all_by_product_id(@product.id, :include => [:property])
@selected_variant = @variants.detect { |v| v.available? }

referer = request.env['HTTP_REFERER']

if referer && referer.match(HTTP_REFERER_REGEXP)
@taxon = Taxon.find_by_permalink($1)
end
@taxon = Taxon.find_by_permalink($1) if referer && referer.match(HTTP_REFERER_REGEXP)
end

def collection
def index
@searcher = Spree::Config.searcher_class.new(params)
@products = @searcher.retrieve_products
end

private

def accurate_title
@product ? @product.name : nil
end

end
15 changes: 5 additions & 10 deletions core/app/controllers/taxons_controller.rb
@@ -1,23 +1,18 @@
class TaxonsController < Spree::BaseController
#prepend_before_filter :reject_unknown_object, :only => [:show]
before_filter :load_data, :only => :show
resource_controller
actions :show

helper :products

private
def load_data
@taxon ||= object
def show
@taxon = Taxon.find_by_permalink(params[:id])
params[:taxon] = @taxon.id
@searcher = Spree::Config.searcher_class.new(params)
@products = @searcher.retrieve_products
end

def object
@object ||= end_of_association_chain.find_by_permalink(params[:id])
end
private

def accurate_title
@taxon ? @taxon.name : nil
end

end
4 changes: 2 additions & 2 deletions core/app/views/admin/adjustments/index.html.erb
@@ -1,4 +1,4 @@
<%= render 'admin/shared/new_adjustment_button' %>
<%= render :partial => 'admin/shared/order_tabs', :locals => {:current => "Adjustments"} %>
<%= render 'admin/shared/adjustments_table' %>
<%= button_link_to t('continue'), @order.cart? ? new_admin_order_payment_url(@order) : admin_orders_url %>
<%= render 'adjustments_table' %>
<%= button_link_to t('continue'), @order.cart? ? new_admin_order_payment_url(@order) : admin_orders_url %>
1 change: 1 addition & 0 deletions core/app/views/admin/adjustments/new.html.erb
Expand Up @@ -3,6 +3,7 @@
<h2><%= t("new_adjustment")%></h2>

<%= render "shared/error_messages", :target => @adjustment %>
<%= form_for @adjustment, :url => collection_url do |f| %>
<%= render :partial => "form", :locals => {:f => f} %>

Expand Down
9 changes: 6 additions & 3 deletions core/features/admin/configuration/analytics_tracker.feature
@@ -1,12 +1,15 @@
Feature: Admin > configurations > analytics_tracker
Feature: analytics tracker

Scenario: Admin > configurations > analytics_tracker
Scenario: index
Given 2 trackers exist
Given I go to the admin home page
When I follow "Configuration"
When I follow "Analytics Tracker"
Then I should see "Analytics Trackers"
Then verify tabular data for tracker index

Scenario: admin updating analytics tracker

Scenario: create
Given I go to the admin home page
When I follow "Configuration"
When I follow "Analytics Trackers"
Expand Down
1 change: 1 addition & 0 deletions core/features/admin/configuration/shipping_methods.feature
@@ -1,6 +1,7 @@
Feature: Admin > configurations > shipping_methods

Scenario: Admin > configurations > shipping_methods
Given I go to the admin home page
When I follow "Configuration"
Given 2 shipping methods exist
When I follow "Shipping Methods"
Expand Down
1 change: 1 addition & 0 deletions core/features/admin/configuration/states.feature
@@ -1,6 +1,7 @@
Feature: Admin > configurations > tax_categories

Scenario: Visiting admin configurations states
Given I go to the admin home page
When I follow "Configuration"
When I follow "States"
Then I should see listing states tabular attributes
1 change: 1 addition & 0 deletions core/features/admin/configuration/taxonomies.feature
@@ -1,6 +1,7 @@
Feature: Admin > configurations > taxonomies

Scenario: Admin > configurations > taxonomies
Given I go to the admin home page
When I follow "Configuration"
Given 2 taxonomies exist
When I follow "Taxonomies"
Expand Down
41 changes: 41 additions & 0 deletions core/features/admin/orders/adjustments.feature
@@ -1,9 +1,35 @@
Feature: Admin visiting orders

Scenario: adjustments index
Given the following orders exist:
|completed at | number |
|2011-02-01 12:36:15 | R100 |
Given an adjustment exists for order R100
And I go to the admin home page
When I follow the first admin_edit_order link
When I follow "Adjustments"
Then I should see tabular attributes for adjustments index

Scenario: new adjustments with validation error
Given the following orders exist:
|completed at | number |
|2011-02-01 12:36:15 | R100 |
Given an adjustment exists for order R100
And I go to the admin home page
When I follow the first admin_edit_order link
When I follow "Adjustments"
When I follow "New Adjustment" custom
When I fill in "adjustment_amount" with ""
When I fill in "adjustment_label" with ""
When I press "Continue"
Then I should see "Label can't be blank"
Then I should see "Amount is not a number"

Scenario: new adjustments
Given the following orders exist:
|completed at | number |
|2011-02-01 12:36:15 | R100 |
Given an adjustment exists for order R100
And I go to the admin home page
When I follow the first admin_edit_order link
When I follow "Adjustments"
Expand All @@ -28,3 +54,18 @@ Feature: Admin visiting orders
Then I should see "Successfully updated!"
Then I should see "rebate 99"
Then I should see "$99.00"

Scenario: edit adjustments with validation error
Given the following orders exist:
|completed at | number |
|2011-02-01 12:36:15 | R100 |
Given an adjustment exists for order R100
And I go to the admin home page
When I follow the first admin_edit_order link
When I follow "Adjustments"
When I click first link from selector "table.index td.actions a.edit"
When I fill in "adjustment_amount" with ""
When I fill in "adjustment_label" with ""
When I press "Continue"
Then I should see "Label can't be blank"
Then I should see "Amount is not a number"
7 changes: 7 additions & 0 deletions core/features/products.feature
Expand Up @@ -7,6 +7,13 @@ Feature: Visiting products
| Categories |
Given the custom taxons and custom products exist

Scenario: show page
When I go to the home page
When I click first link from selector "ul.product-listing a"
Then I should see "$17.99"
When I click first link from selector "form button.primary"
Then I should see "Shopping Cart"

Scenario: visit products page
When I go to the home page
When I fill in "keywords" with "shirt"
Expand Down
14 changes: 14 additions & 0 deletions core/features/step_definitions/admin/configurations.rb
Expand Up @@ -83,3 +83,17 @@
data = output[1]
data[0].should == TaxCategory.limit(1).order('name asc').to_a.first.name
end

Then /^verify tabular data for tracker index$/ do
output = tableish('table.index tr', 'td,th')
data = output[0]
data[0].should == 'Analytics ID'
data[1].should == 'Environment'
data[2].should == 'Active'
data[3].should == 'Action'

data = output[1]
data[0].should == 'A100'
data[1].should == 'Cucumber'
data[2].should == 'Yes'
end

0 comments on commit aa236a7

Please sign in to comment.