Skip to content

Commit

Permalink
FIX: Using shop#url instead of shop#name to save and identify the Sho…
Browse files Browse the repository at this point in the history
…p locally.
  • Loading branch information
Soleone committed May 29, 2009
1 parent ffe6bc6 commit 0b9042c
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ApplicationController < ActionController::Base
protected

def shop
Shop.find_by_name(session[:shopify].name)
Shop.find_or_create_by_url(current_shop.url)
end

end
2 changes: 1 addition & 1 deletion app/controllers/login_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def finalize
session[:shopify] = shopify_session

# save shop to local DB
@shop = Shop.find_or_create_by_name(shopify_session.name)
@shop = Shop.find_or_create_by_url(shopify_session.url)

flash[:notice] = "Successfully logged into shopify store."

Expand Down
13 changes: 0 additions & 13 deletions app/models/example_order.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/models/print_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PrintTemplate < ActiveRecord::Base

def self.create_from_file(template_name)
content = File.read("#{RAILS_ROOT}/db/printing/#{template_name}.liquid")
create(:name => template_name.to_s, :body => content)
create(:name => template_name.to_s.capitalize, :body => content)
end

def parse
Expand Down
13 changes: 13 additions & 0 deletions db/migrate/20090529202856_create_shop_url_remove_shop_name.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateShopUrlRemoveShopName < ActiveRecord::Migration
def self.up
remove_column :shops, :name
add_column :shops, :url, :string
add_index :shops, :url
end

def self.down
add_column :shops, :name, :string
remove_column :shops, :url
remove_index :shops, :url
end
end
6 changes: 3 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20090527192110) do
ActiveRecord::Schema.define(:version => 20090529202856) do

create_table "print_templates", :force => true do |t|
t.integer "shop_id"
Expand All @@ -23,11 +23,11 @@
add_index "print_templates", ["shop_id"], :name => "index_print_templates_on_shop_id"

create_table "shops", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
t.string "url"
end

add_index "shops", ["name"], :name => "index_shops_on_name"
add_index "shops", ["url"], :name => "index_shops_on_url"

end
2 changes: 1 addition & 1 deletion test/fixtures/shops.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

germanbrownies:
name: German Brownies
url: german-brownies.myshopify.com
7 changes: 4 additions & 3 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ def shop(file = 'shop.xml', overwrites = {})
ShopifyAPI::Shop.new(shop_hash)
end

def login_session(shop_name)
Shop.stubs(:find_by_name).returns(shops(shop_name))
{:shopify => ShopifyAPI::Session.new(shop_name.to_s, 'somerandomtoken')}
def login_session(shop_fixture)
shop = shops(shop_fixture)
Shop.stubs(:find_by_url).returns(shop)
{:shopify => ShopifyAPI::Session.new(shop.url, 'somerandomtoken')}
end

# ====================
Expand Down
6 changes: 3 additions & 3 deletions test/unit/print_template_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class PrintTemplateTest < ActiveSupport::TestCase
before do
ActiveResource::Base.site = 'http://any-url-for-testing'
@local_shop = Shop.create(:name => "My Shop")
@local_shop = shops(:germanbrownies)
@remote_us_shop = shop('shop.xml', {'currency' => "USD", 'money_format' => "$ {{amount}}"})
@remote_european_shop = shop('shop.xml', {'currency' => "EUR", 'money_format' => "&euro;{{amount}}"})
end
Expand All @@ -15,7 +15,7 @@ class PrintTemplateTest < ActiveSupport::TestCase

should "allow the same name for different shops" do
assert @local_shop.templates.create(:name => "My name", :body => "whatever").valid?
assert Shop.create(:name => "My other Shop").templates.create(:name => "My name", :body => "something else").valid?
assert Shop.create(:url => "www.differentshop.com").templates.create(:name => "My name", :body => "something else").valid?
end

should "not allow more than 10 templates per shop" do
Expand All @@ -34,7 +34,7 @@ class PrintTemplateTest < ActiveSupport::TestCase

should "save body and name from that serialized template" do
template = @local_shop.templates.create_from_file(:invoice)
assert_equal 'invoice', template.name
assert_equal 'Invoice', template.name
assert_equal File.read("#{RAILS_ROOT}/db/printing/invoice.liquid"), template.body
end
end
Expand Down

0 comments on commit 0b9042c

Please sign in to comment.