From f6a25df33395c6f226685ba9297ce2408abc14e3 Mon Sep 17 00:00:00 2001 From: saberma Date: Sun, 29 Jul 2012 13:49:56 +0800 Subject: [PATCH 01/35] upgrade devise to 1.5 first --- Gemfile | 2 +- Gemfile.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index 0258cd13..b5150596 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,7 @@ gem 'rails', '3.2.6' ##### 实体相关 ##### gem 'pg' -gem 'devise', '~> 1.4.9' +gem 'devise', '~> 1.5.0' gem 'sass-rails' # 放在assets分组会报错 http://j.mp/oj7y6K diff --git a/Gemfile.lock b/Gemfile.lock index 7ccfc251..1bb5f968 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -159,10 +159,10 @@ GEM database_cleaner (0.6.7) decent_exposure (1.0.1) default_value_for (1.0.5) - devise (1.4.9) + devise (1.5.3) bcrypt-ruby (~> 3.0) orm_adapter (~> 0.0.3) - warden (~> 1.0.3) + warden (~> 1.1) diff-lcs (1.1.3) doorkeeper (0.4.0) railties (~> 3.1) @@ -413,7 +413,7 @@ GEM macaddr (~> 1.0) vegas (0.1.8) rack (>= 1.0.0) - warden (1.0.6) + warden (1.2.1) rack (>= 1.0) webmock (1.7.10) addressable (~> 2.2, > 2.2.5) @@ -441,7 +441,7 @@ DEPENDENCIES database_cleaner decent_exposure default_value_for - devise (~> 1.4.9) + devise (~> 1.5.0) doorkeeper (~> 0.4.0) dragonfly (~> 0.9.8) exception_notification From 41c58da5303d53f5ec53924eca20db18816a8a27 Mon Sep 17 00:00:00 2001 From: saberma Date: Sun, 29 Jul 2012 16:15:08 +0800 Subject: [PATCH 02/35] redirect_location is deprecated, please use after_sign_in_path_for. --- app/controllers/shop/passwords_controller.rb | 2 +- app/controllers/shop/registrations_controller.rb | 7 +------ app/controllers/shop/sessions_controller.rb | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/app/controllers/shop/passwords_controller.rb b/app/controllers/shop/passwords_controller.rb index 0693e910..2c234bd3 100644 --- a/app/controllers/shop/passwords_controller.rb +++ b/app/controllers/shop/passwords_controller.rb @@ -46,7 +46,7 @@ def update flash_message = resource.active_for_authentication? ? :updated : :updated_not_active set_flash_message(:notice, flash_message) if is_navigational_format? sign_in(resource_name, resource) - respond_with resource, :location => redirect_location(resource_name, resource) + respond_with resource, location: after_sign_in_path_for(resource) else path = theme.template_path('customers/reset_password') path = Rails.root.join 'app/views/shop/templates/customers/reset_password.liquid' unless File.exist?(path) diff --git a/app/controllers/shop/registrations_controller.rb b/app/controllers/shop/registrations_controller.rb index 1b41d188..6d2de56a 100644 --- a/app/controllers/shop/registrations_controller.rb +++ b/app/controllers/shop/registrations_controller.rb @@ -38,7 +38,7 @@ def create end redirect_to checkout_url and return else - respond_with resource, :location => redirect_location(resource_name, resource) + respond_with resource, location: after_sign_in_path_for(resource_name, resource) end else set_flash_message :notice, :inactive_signed_up, :reason => inactive_reason(resource) if is_navigational_format? @@ -111,11 +111,6 @@ def after_sign_up_path_for(resource) after_sign_in_path_for(resource) end - # Overwrite redirect_for_sign_in so it takes uses after_sign_up_path_for. - def redirect_location(scope, resource) - stored_location_for(scope) || after_sign_up_path_for(resource) - end - # Returns the inactive reason translated. def inactive_reason(resource) reason = resource.inactive_message.to_s diff --git a/app/controllers/shop/sessions_controller.rb b/app/controllers/shop/sessions_controller.rb index d17d59ff..c6a5057f 100644 --- a/app/controllers/shop/sessions_controller.rb +++ b/app/controllers/shop/sessions_controller.rb @@ -49,7 +49,7 @@ def create end redirect_to checkout_url and return else - respond_with resource, :location => redirect_location(resource_name, resource) + respond_with resource, location: after_sign_in_path_for(resource) end end From 33af9ed3bd530c7049af0eba94f96ed6d8ee4051 Mon Sep 17 00:00:00 2001 From: saberma Date: Sun, 29 Jul 2012 23:21:56 +0800 Subject: [PATCH 03/35] remove devise migration helper. --- .../20110420064741_devise_create_users.rb | 44 +++- db/migrate/20110622024506_create_customers.rb | 45 +++- ...0110926051845_devise_create_admin_users.rb | 46 +++- ...120729084444_make_timestamps_null_false.rb | 22 ++ db/migrate/20120729144327_upgrade_devise.rb | 7 + db/schema.rb | 207 +++++++++--------- 6 files changed, 246 insertions(+), 125 deletions(-) create mode 100644 db/migrate/20120729084444_make_timestamps_null_false.rb create mode 100644 db/migrate/20120729144327_upgrade_devise.rb diff --git a/db/migrate/20110420064741_devise_create_users.rb b/db/migrate/20110420064741_devise_create_users.rb index c5e8ccab..8709903e 100644 --- a/db/migrate/20110420064741_devise_create_users.rb +++ b/db/migrate/20110420064741_devise_create_users.rb @@ -2,10 +2,24 @@ class DeviseCreateUsers < ActiveRecord::Migration def self.up create_table(:users) do |t| - t.database_authenticatable :null => false - t.recoverable - t.rememberable - t.trackable + ## Database authenticatable + t.string :email, :null => false, :default => "" + t.string :encrypted_password, :null => false, :default => "", :limit => 128 + + ## Recoverable + t.string :reset_password_token + # t.datetime :reset_password_sent_at + + ## Rememberable + t.datetime :remember_created_at + + ## Trackable + t.integer :sign_in_count, :default => 0 + t.datetime :current_sign_in_at + t.datetime :last_sign_in_at + t.string :current_sign_in_ip + t.string :last_sign_in_ip + t.string :name, comment:"姓名" t.string :phone, comment:"电话" t.text :bio,comment:"用户介绍" @@ -16,11 +30,25 @@ def self.up #增加用户权限 t.boolean :admin, default: true - # t.encryptable - # t.confirmable - # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both - t.token_authenticatable + ## Encryptable + # t.string :password_salt + + ## Confirmable + # t.string :confirmation_token + # t.datetime :confirmed_at + # t.datetime :confirmation_sent_at + # t.string :unconfirmed_email # Only if using reconfirmable + + ## Lockable + # t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts + # t.string :unlock_token # Only if unlock strategy is :email or :both + # t.datetime :locked_at + + # Token authenticatable + t.string :authentication_token + ## Invitable + # t.string :invitation_token t.timestamps end diff --git a/db/migrate/20110622024506_create_customers.rb b/db/migrate/20110622024506_create_customers.rb index 9c4deda4..df550e30 100644 --- a/db/migrate/20110622024506_create_customers.rb +++ b/db/migrate/20110622024506_create_customers.rb @@ -10,15 +10,48 @@ def self.up t.float :total_spent , comment: "消费总额" , default: 0 t.integer :orders_count , comment: "缓存订单数" , default: 0 t.boolean :accepts_marketing, comment: "是否接收营销邮件", default: true + begin '顾客登陆信息' - t.database_authenticatable :null => false - t.recoverable - t.rememberable - t.trackable - t.token_authenticatable - end + ## Database authenticatable + t.string :email, :null => false, :default => "" + t.string :encrypted_password, :null => false, :default => "", :limit => 128 + + ## Recoverable + t.string :reset_password_token + # t.datetime :reset_password_sent_at + + ## Rememberable + t.datetime :remember_created_at + + ## Trackable + t.integer :sign_in_count, :default => 0 + t.datetime :current_sign_in_at + t.datetime :last_sign_in_at + t.string :current_sign_in_ip + t.string :last_sign_in_ip + + ## Encryptable + # t.string :password_salt + + ## Confirmable + # t.string :confirmation_token + # t.datetime :confirmed_at + # t.datetime :confirmation_sent_at + # t.string :unconfirmed_email # Only if using reconfirmable + + ## Lockable + # t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts + # t.string :unlock_token # Only if unlock strategy is :email or :both + # t.datetime :locked_at + + # Token authenticatable + t.string :authentication_token + + ## Invitable + # t.string :invitation_token t.timestamps + end end #地址信息 diff --git a/db/migrate/20110926051845_devise_create_admin_users.rb b/db/migrate/20110926051845_devise_create_admin_users.rb index 0dbd5733..495218a3 100644 --- a/db/migrate/20110926051845_devise_create_admin_users.rb +++ b/db/migrate/20110926051845_devise_create_admin_users.rb @@ -1,15 +1,43 @@ class DeviseCreateAdminUsers < ActiveRecord::Migration def self.up create_table(:admin_users) do |t| - t.database_authenticatable :null => false - t.recoverable - t.rememberable - t.trackable - - # t.encryptable - # t.confirmable - # t.lockable :lock_strategy => :failed_attempts, :unlock_strategy => :both - # t.token_authenticatable + ## Database authenticatable + t.string :email, :null => false, :default => "" + t.string :encrypted_password, :null => false, :default => "", :limit => 128 + + ## Recoverable + t.string :reset_password_token + # t.datetime :reset_password_sent_at + + ## Rememberable + t.datetime :remember_created_at + + ## Trackable + t.integer :sign_in_count, :default => 0 + t.datetime :current_sign_in_at + t.datetime :last_sign_in_at + t.string :current_sign_in_ip + t.string :last_sign_in_ip + + ## Encryptable + # t.string :password_salt + + ## Confirmable + # t.string :confirmation_token + # t.datetime :confirmed_at + # t.datetime :confirmation_sent_at + # t.string :unconfirmed_email # Only if using reconfirmable + + ## Lockable + # t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts + # t.string :unlock_token # Only if unlock strategy is :email or :both + # t.datetime :locked_at + + # Token authenticatable + # t.string :authentication_token + + ## Invitable + # t.string :invitation_token t.timestamps end diff --git a/db/migrate/20120729084444_make_timestamps_null_false.rb b/db/migrate/20120729084444_make_timestamps_null_false.rb new file mode 100644 index 00000000..015b542d --- /dev/null +++ b/db/migrate/20120729084444_make_timestamps_null_false.rb @@ -0,0 +1,22 @@ +class MakeTimestampsNullFalse < ActiveRecord::Migration + def up + ["shippings", "weight_based_shipping_rates", "shop_themes", "shop_theme_settings", "shop_policies", "price_based_shipping_rates", "shop_tasks", "users", "products", "photos", "link_lists", "links", "product_variants", "kindeditors", "pages", "smart_collections", "smart_collection_rules", "smart_collection_products", "custom_collections", "custom_collection_products", "blogs", "articles", "comments", "tags", "order_fulfillments", "orders", "carts", "emails", "subscribes", "customers", "customer_tags", "customer_groups", "activities", "consumptions", "admin_users", "active_admin_comments", "payments", "api_clients", "cancel_reasons", "shops", "oauth_applications"].each do |table| + change_column table, :created_at, :datetime , null: false + change_column table, :updated_at, :datetime , null: false + end + ["order_histories", "order_transactions", "webhooks"].each do |table| + change_column table, :created_at, :datetime , null: false + end + end + + def down + ["shippings", "weight_based_shipping_rates", "shop_themes", "shop_theme_settings", "shop_policies", "price_based_shipping_rates", "shop_tasks", "users", "products", "photos", "link_lists", "links", "product_variants", "kindeditors", "pages", "smart_collections", "smart_collection_rules", "smart_collection_products", "custom_collections", "custom_collection_products", "blogs", "articles", "comments", "tags", "order_fulfillments", "orders", "carts", "emails", "subscribes", "customers", "customer_tags", "customer_groups", "activities", "consumptions", "admin_users", "active_admin_comments", "payments", "api_clients", "cancel_reasons", "shops", "oauth_applications"].each do |table| + change_column table, :created_at, :datetime , null: true + change_column table, :updated_at, :datetime , null: true + end + #["order_histories", "order_transactions", "webhooks", "oauth_access_grants", "oauth_access_tokens"].each do |table| + ["order_histories", "order_transactions", "webhooks"].each do |table| + change_column table, :created_at, :datetime , null: true + end + end +end diff --git a/db/migrate/20120729144327_upgrade_devise.rb b/db/migrate/20120729144327_upgrade_devise.rb new file mode 100644 index 00000000..3922f261 --- /dev/null +++ b/db/migrate/20120729144327_upgrade_devise.rb @@ -0,0 +1,7 @@ +class UpgradeDevise < ActiveRecord::Migration + def change + add_column :users , :reset_password_sent_at, :datetime + add_column :admin_users, :reset_password_sent_at, :datetime + add_column :customers , :reset_password_sent_at, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 89961694..da986458 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120707020959) do +ActiveRecord::Schema.define(:version => 20120729144327) do create_table "active_admin_comments", :force => true do |t| t.integer "resource_id", :null => false @@ -20,8 +20,8 @@ t.integer "author_id" t.string "namespace" t.text "body" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "active_admin_comments", ["author_type", "author_id"], :name => "index_active_admin_comments_on_author_type_and_author_id" @@ -34,22 +34,23 @@ t.integer "user_id" t.integer "shop_id" t.string "class_name" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "admin_users", :force => true do |t| - t.string "email", :default => "", :null => false - t.string "encrypted_password", :limit => 128, :default => "", :null => false + t.string "email", :default => "", :null => false + t.string "encrypted_password", :limit => 128, :default => "", :null => false t.string "reset_password_token" t.datetime "remember_created_at" - t.integer "sign_in_count", :default => 0 + t.integer "sign_in_count", :default => 0 t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.datetime "reset_password_sent_at" end add_index "admin_users", ["email"], :name => "index_admin_users_on_email", :unique => true @@ -61,8 +62,8 @@ t.string "password", :limit => 32 t.string "shared_secret", :limit => 32 t.string "title", :limit => 36 - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "articles", :force => true do |t| @@ -73,8 +74,8 @@ t.boolean "published", :default => true t.integer "user_id" t.string "author" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "articles", ["blog_id"], :name => "index_articles_on_blog_id" @@ -92,8 +93,8 @@ t.string "title", :null => false t.string "commentable" t.string "handle", :null => false - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "blogs", ["shop_id"], :name => "index_blogs_on_shop_id" @@ -101,8 +102,8 @@ create_table "cancel_reasons", :force => true do |t| t.string "selection" t.string "detailed" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "carts", :force => true do |t| @@ -111,8 +112,8 @@ t.string "session_id", :limit => 32, :null => false t.string "cart_hash", :null => false t.integer "customer_id" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "carts", ["shop_id"], :name => "index_carts_on_shop_id" @@ -125,8 +126,8 @@ t.string "author" t.string "email" t.text "body" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "comments", ["article_id"], :name => "index_comments_on_article_id" @@ -138,16 +139,16 @@ t.float "price" t.boolean "status" t.integer "plan_type_id" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "custom_collection_products", :force => true do |t| t.integer "custom_collection_id" t.integer "product_id" t.integer "position" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "custom_collection_products", ["custom_collection_id"], :name => "index_custom_collection_products_on_custom_collection_id" @@ -159,8 +160,8 @@ t.string "handle", :null => false t.text "body_html" t.string "products_order" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "custom_collections", ["shop_id"], :name => "index_custom_collections_on_shop_id" @@ -186,8 +187,8 @@ t.string "name", :limit => 32, :null => false t.string "term", :limit => 32 t.string "query", :limit => 512 - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "customer_groups", ["shop_id"], :name => "index_customer_groups_on_shop_id" @@ -195,8 +196,8 @@ create_table "customer_tags", :force => true do |t| t.integer "shop_id", :null => false t.string "name", :null => false - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "customer_tags", ["shop_id"], :name => "index_customer_tags_on_shop_id" @@ -210,25 +211,26 @@ add_index "customer_tags_customers", ["customer_tag_id"], :name => "index_customer_tags_customers_on_customer_tag_id" create_table "customers", :force => true do |t| - t.integer "shop_id", :null => false - t.string "status", :limit => 8, :null => false - t.string "name", :limit => 16, :null => false + t.integer "shop_id", :null => false + t.string "status", :limit => 8, :null => false + t.string "name", :limit => 16, :null => false t.string "note" - t.float "total_spent", :default => 0.0 - t.integer "orders_count", :default => 0 - t.boolean "accepts_marketing", :default => true - t.string "email", :default => "", :null => false - t.string "encrypted_password", :limit => 128, :default => "", :null => false + t.float "total_spent", :default => 0.0 + t.integer "orders_count", :default => 0 + t.boolean "accepts_marketing", :default => true + t.string "email", :default => "", :null => false + t.string "encrypted_password", :limit => 128, :default => "", :null => false t.string "reset_password_token" t.datetime "remember_created_at" - t.integer "sign_in_count", :default => 0 + t.integer "sign_in_count", :default => 0 t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" t.string "authentication_token" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.datetime "reset_password_sent_at" end add_index "customers", ["shop_id", "email"], :name => "index_customers_on_shop_id_and_email", :unique => true @@ -250,15 +252,15 @@ t.text "body", :null => false t.boolean "include_html", :default => false t.text "body_html" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "kindeditors", :force => true do |t| t.integer "shop_id", :null => false t.string "kindeditor_image_uid" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "link_lists", :force => true do |t| @@ -266,8 +268,8 @@ t.string "title" t.string "handle" t.boolean "system_default", :default => false - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "link_lists", ["shop_id"], :name => "index_link_lists_on_shop_id" @@ -280,8 +282,8 @@ t.string "subject_params" t.string "url" t.integer "position" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "links", ["link_list_id"], :name => "index_links_on_link_list_id" @@ -319,8 +321,8 @@ t.string "uid", :limit => 64, :null => false t.string "secret", :limit => 64, :null => false t.string "redirect_uri", :null => false - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "oauth_applications", ["uid"], :name => "index_oauth_applications_on_uid", :unique => true @@ -335,8 +337,8 @@ t.integer "order_id", :null => false t.string "tracking_number" t.string "tracking_company" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "order_fulfillments", ["order_id"], :name => "index_order_fulfillments_on_order_id" @@ -353,7 +355,7 @@ t.integer "order_id", :null => false t.string "body", :null => false t.string "url", :limit => 64 - t.datetime "created_at" + t.datetime "created_at", :null => false end add_index "order_histories", ["order_id"], :name => "index_order_histories_on_order_id" @@ -395,7 +397,7 @@ t.integer "order_id", :null => false t.string "kind", :limit => 16, :null => false t.float "amount" - t.datetime "created_at" + t.datetime "created_at", :null => false end add_index "order_transactions", ["order_id"], :name => "index_order_transactions_on_order_id" @@ -419,8 +421,8 @@ t.datetime "closed_at" t.string "cancel_reason", :limit => 16 t.datetime "cancelled_at" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.float "subtotal_price" t.string "trade_no", :limit => 16 end @@ -435,8 +437,8 @@ t.boolean "published", :default => false t.string "handle", :null => false t.text "body_html" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "pages", ["shop_id"], :name => "index_pages_on_shop_id" @@ -449,8 +451,8 @@ t.string "account" t.text "message" t.string "name" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "service", :limit => 32 end @@ -466,8 +468,8 @@ t.string "product_image_uid" t.string "product_image_format" t.integer "position" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "photos", ["product_id"], :name => "index_photos_on_product_id" @@ -477,8 +479,8 @@ t.float "min_order_subtotal" t.float "max_order_subtotal" t.string "name", :limit => 32 - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.integer "shipping_id" end @@ -506,8 +508,8 @@ t.integer "inventory_quantity" t.string "inventory_management" t.string "inventory_policy", :default => "deny" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.integer "position" end @@ -522,8 +524,8 @@ t.float "price" t.string "product_type" t.string "vendor" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "products", ["shop_id"], :name => "index_products_on_shop_id" @@ -539,8 +541,8 @@ create_table "shippings", :force => true do |t| t.integer "shop_id" t.string "code", :limit => 8 - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "shippings", ["shop_id"], :name => "index_shippings_on_shop_id" @@ -563,8 +565,8 @@ t.string "title" t.text "body" t.integer "shop_id" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "shop_policies", ["shop_id"], :name => "index_shop_policies_on_shop_id" @@ -587,8 +589,8 @@ t.integer "shop_id" t.string "name" t.boolean "completed", :default => false - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "shop_tasks", ["shop_id"], :name => "index_shop_tasks_on_shop_id" @@ -597,8 +599,8 @@ t.integer "shop_theme_id", :null => false t.string "name", :limit => 64, :null => false t.string "value", :limit => 128 - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "shop_theme_settings", ["shop_theme_id"], :name => "index_shop_theme_settings_on_shop_theme_id" @@ -609,8 +611,8 @@ t.string "name", :limit => 32, :null => false t.string "role", :limit => 16, :null => false t.string "load_preset", :limit => 16 - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "shop_themes", ["shop_id"], :name => "index_shop_themes_on_shop_id" @@ -639,8 +641,8 @@ t.string "customer_accounts", :default => "optional" t.string "signup_source", :limit => 16 t.boolean "guided", :default => false - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.boolean "access_enabled", :default => true end @@ -648,8 +650,8 @@ t.integer "smart_collection_id" t.integer "product_id" t.integer "position" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "smart_collection_products", ["smart_collection_id"], :name => "index_smart_collection_products_on_smart_collection_id" @@ -659,8 +661,8 @@ t.string "column" t.string "relation" t.string "condition" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "smart_collection_rules", ["smart_collection_id"], :name => "index_smart_collection_rules_on_smart_collection_id" @@ -672,8 +674,8 @@ t.string "handle", :null => false t.text "body_html" t.string "products_order" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "smart_collections", ["shop_id"], :name => "index_smart_collections_on_shop_id" @@ -684,16 +686,16 @@ t.string "kind" t.string "address" t.string "number" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "tags", :force => true do |t| t.integer "shop_id", :null => false t.string "name", :null => false t.integer "category" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end add_index "tags", ["shop_id"], :name => "index_tags_on_shop_id" @@ -725,11 +727,11 @@ end create_table "users", :force => true do |t| - t.string "email", :default => "", :null => false - t.string "encrypted_password", :limit => 128, :default => "", :null => false + t.string "email", :default => "", :null => false + t.string "encrypted_password", :limit => 128, :default => "", :null => false t.string "reset_password_token" t.datetime "remember_created_at" - t.integer "sign_in_count", :default => 0 + t.integer "sign_in_count", :default => 0 t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" @@ -737,13 +739,14 @@ t.string "name" t.string "phone" t.text "bio" - t.boolean "receive_announcements", :default => true + t.boolean "receive_announcements", :default => true t.integer "shop_id" t.string "avatar_image_uid" - t.boolean "admin", :default => true + t.boolean "admin", :default => true t.string "authentication_token" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.datetime "reset_password_sent_at" end add_index "users", ["authentication_token"], :name => "index_users_on_authentication_token", :unique => true @@ -764,8 +767,8 @@ t.float "weight_low" t.float "weight_high" t.string "name", :limit => 32 - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.integer "shipping_id" end From 3aaf99779c3a77d1cff27085e81fc3ebbb6aef98 Mon Sep 17 00:00:00 2001 From: saberma Date: Sun, 29 Jul 2012 23:31:27 +0800 Subject: [PATCH 04/35] update devise locale information. --- config/initializers/devise.rb | 11 ++--------- config/locales/devise.cn.yml | 4 +++- config/locales/devise.en.yml | 4 +++- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 7f59d5f6..8d7c5cb8 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -60,11 +60,11 @@ # ==> Configuration for :confirmable # The time you want to give your user to confirm his account. During this time # he will be able to access your application without confirming. Default is 0.days - # When confirm_within is zero, the user won't be able to sign in without confirming. + # When allow_unconfirmed_access_for is zero, the user won't be able to sign in without confirming. # You can use this to let your user access some features of your application # without confirming the account, but blocking it after a certain period # (ie 2 days). - # config.confirm_within = 2.days + # config.allow_unconfirmed_access_for = 2.days # Defines which key will be used when confirming an account # config.confirmation_keys = [ :email ] @@ -73,9 +73,6 @@ # The time the user will be remembered without asking for credentials again. config.remember_for = 2.weeks - # If true, a valid remember token can be re-used between multiple browsers. - config.remember_across_browsers = true - # If true, extends the user's remember period when remembered via cookie. config.extend_remember_period = true @@ -135,10 +132,6 @@ # Defines name of the authentication token params key config.token_authentication_key = :login_token - # If true, authentication through token does not store user in session and needs - # to be supplied on each request. Useful if you are using the token as API token. - # config.stateless_token = false - # ==> Scopes configuration # Turn scoped views on. Before rendering "sessions/new", it will first check for # "users/sessions/new". It's turned off by default because it's slower if you diff --git a/config/locales/devise.cn.yml b/config/locales/devise.cn.yml index 76e2df2b..ee92cf68 100644 --- a/config/locales/devise.cn.yml +++ b/config/locales/devise.cn.yml @@ -28,9 +28,11 @@ cn: confirmed: '您的帐号已经激活,请登录.' registrations: signed_up: '您的帐号已注册成功,如无意外,您将地收到一封确认邮件.' - inactive_signed_up: '您的帐号已注册成功,但由于%{reason}我们无法让您登录.' updated: '帐号资料更新成功.' destroyed: '再见!您的帐户已成功注销。我们希望很快可以再见到您.' + signed_up_but_unconfirmed: '我们已经发送一封带有确认链接的邮件到您的邮箱,请先打开这个链接进行确认.' + signed_up_but_inactive: '您的帐号已注册成功,但还没有激活.' + signed_up_but_locked: '您的帐号已注册成功,但是处于锁定状态.' unlocks: send_instructions: '几分后,您将收到一封帐号解锁的邮件.' unlocked: '您的帐号已成功解锁,请登录.' diff --git a/config/locales/devise.en.yml b/config/locales/devise.en.yml index e70ad899..8855f8f6 100644 --- a/config/locales/devise.en.yml +++ b/config/locales/devise.en.yml @@ -30,9 +30,11 @@ en: confirmed: 'Your account was successfully confirmed. You are now signed in.' registrations: signed_up: 'Welcome! You have signed up successfully.' - inactive_signed_up: 'You have signed up successfully. However, we could not sign you in because your account is %{reason}.' updated: 'You updated your account successfully.' destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.' + signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.' + signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.' + signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.' unlocks: send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.' unlocked: 'Your account was successfully unlocked. You are now signed in.' From 58adbcf4846a74a349067a2f7b36b859b652d119 Mon Sep 17 00:00:00 2001 From: saberma Date: Sun, 29 Jul 2012 23:44:16 +0800 Subject: [PATCH 05/35] remove render_with_scope. --- .../shop/registrations_controller.rb | 32 ------------------- 1 file changed, 32 deletions(-) diff --git a/app/controllers/shop/registrations_controller.rb b/app/controllers/shop/registrations_controller.rb index 6d2de56a..e83e3bb7 100644 --- a/app/controllers/shop/registrations_controller.rb +++ b/app/controllers/shop/registrations_controller.rb @@ -1,7 +1,6 @@ #encoding: utf-8 class Shop::RegistrationsController < Shop::AppController prepend_before_filter :require_no_authentication, :only => [ :new, :create, :cancel ] - prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy] skip_before_filter :must_has_theme include Devise::Controllers::InternalHelpers include Shop::OrderHelper @@ -18,7 +17,6 @@ def new assign.merge!('content_for_layout' => liquid_view) html = Liquid::Template.parse(layout_content).render(shop_assign(assign)) render text: html - #render_with_scope :new end # POST /resource @@ -47,7 +45,6 @@ def create end else clean_up_passwords(resource) - #render_with_scope :new path = Rails.root.join 'app/views/shop/templates/customers/registrations.liquid' assign = template_assign('template' => 'customers', 'customer' => CustomerDrop.new(resource)) liquid_view = Liquid::Template.parse(File.read(path)).render(assign) @@ -57,35 +54,6 @@ def create end end - # GET /resource/edit - def edit - render_with_scope :edit - end - - # PUT /resource - # We need to use a copy of the resource because we don't want to change - # the current user in place. - def update - self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key) - - if resource.update_with_password(params[resource_name]) - set_flash_message :notice, :updated if is_navigational_format? - sign_in resource_name, resource, :bypass => true - respond_with resource, :location => after_update_path_for(resource) - else - clean_up_passwords(resource) - respond_with_navigational(resource){ render_with_scope :edit } - end - end - - # DELETE /resource - def destroy - resource.destroy - Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name) - set_flash_message :notice, :destroyed if is_navigational_format? - redirect_to after_sign_out_path_for(resource_name) - end - # GET /resource/cancel # Forces the session data which is usually expired after sign # in to be expired now. This is useful if the user wants to From d279ebee1aafe023240cba95c9eaa56580810583 Mon Sep 17 00:00:00 2001 From: saberma Date: Sun, 29 Jul 2012 23:55:18 +0800 Subject: [PATCH 06/35] upgrade devise to 2.0.4 --- Gemfile | 2 +- Gemfile.lock | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index b5150596..e70ee54a 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,7 @@ gem 'rails', '3.2.6' ##### 实体相关 ##### gem 'pg' -gem 'devise', '~> 1.5.0' +gem 'devise', '~> 2.0.0' gem 'sass-rails' # 放在assets分组会报错 http://j.mp/oj7y6K diff --git a/Gemfile.lock b/Gemfile.lock index 1bb5f968..ce43cd18 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -159,10 +159,11 @@ GEM database_cleaner (0.6.7) decent_exposure (1.0.1) default_value_for (1.0.5) - devise (1.5.3) + devise (2.0.4) bcrypt-ruby (~> 3.0) orm_adapter (~> 0.0.3) - warden (~> 1.1) + railties (~> 3.1) + warden (~> 1.1.1) diff-lcs (1.1.3) doorkeeper (0.4.0) railties (~> 3.1) @@ -413,7 +414,7 @@ GEM macaddr (~> 1.0) vegas (0.1.8) rack (>= 1.0.0) - warden (1.2.1) + warden (1.1.1) rack (>= 1.0) webmock (1.7.10) addressable (~> 2.2, > 2.2.5) @@ -441,7 +442,7 @@ DEPENDENCIES database_cleaner decent_exposure default_value_for - devise (~> 1.5.0) + devise (~> 2.0.0) doorkeeper (~> 0.4.0) dragonfly (~> 0.9.8) exception_notification From 79819e5b85d216d0575374a2ebfc46a979867759 Mon Sep 17 00:00:00 2001 From: saberma Date: Mon, 30 Jul 2012 18:06:15 +0800 Subject: [PATCH 07/35] change devise_for to devise_scope. --- config/routes.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index c3f9c5ec..0af6fba4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,7 +16,7 @@ end constraints(Domain::Wiki) do # 帮助文档 - devise_for :admin_users, ActiveAdmin::Devise.config + devise_scope :admin_users, ActiveAdmin::Devise.config scope module: :wiki do get '/' , to: 'wiki_pages#index' , as: :wiki_pages_index get '/active_admin' , to: redirect('/') @@ -100,16 +100,16 @@ mount Resque::Server.new, at: "/resque" # 查看后台任务执行情况 end - devise_for :admin_users, ActiveAdmin::Devise.config + devise_scope :admin_users, ActiveAdmin::Devise.config end constraints(Domain::Store) do - devise_for :user, skip: :registrations, controllers: {sessions: "admin/sessions"}# 登录 + devise_scope :user, skip: :registrations, controllers: {sessions: "admin/sessions"}# 登录 scope module: :shop do # 前台商店 scope '/account' do - devise_for :customer do + devise_scope :customer do get '/login' , to: 'sessions#new' post '/login' , to: 'sessions#create' get '/signup' , to: 'registrations#new' From b8b0309f5ad508f4c66bbd95448e5e24cc9cb166 Mon Sep 17 00:00:00 2001 From: saberma Date: Mon, 30 Jul 2012 23:10:34 +0800 Subject: [PATCH 08/35] remove Devise::Controllers::InternalHelpers --- app/controllers/shop/app_controller.rb | 4 -- app/controllers/shop/passwords_controller.rb | 1 - .../shop/registrations_controller.rb | 12 +---- app/controllers/shop/sessions_controller.rb | 49 ++++--------------- config/initializers/devise.rb | 3 +- config/routes.rb | 9 ++-- 6 files changed, 20 insertions(+), 58 deletions(-) diff --git a/app/controllers/shop/app_controller.rb b/app/controllers/shop/app_controller.rb index a01eefe2..605670e3 100644 --- a/app/controllers/shop/app_controller.rb +++ b/app/controllers/shop/app_controller.rb @@ -176,8 +176,4 @@ def show_errors(exception) # 出错显示404页面 end - def after_sign_in_path_for(resource) - stored_location_for(resource) || customer_account_index_path - end - end diff --git a/app/controllers/shop/passwords_controller.rb b/app/controllers/shop/passwords_controller.rb index 2c234bd3..51acf6be 100644 --- a/app/controllers/shop/passwords_controller.rb +++ b/app/controllers/shop/passwords_controller.rb @@ -1,7 +1,6 @@ #encoding: utf-8 class Shop::PasswordsController < Shop::AppController prepend_before_filter :require_no_authentication - include Devise::Controllers::InternalHelpers skip_before_filter :must_has_theme expose(:shop) { Shop.at(request.host) } diff --git a/app/controllers/shop/registrations_controller.rb b/app/controllers/shop/registrations_controller.rb index e83e3bb7..66bdeb15 100644 --- a/app/controllers/shop/registrations_controller.rb +++ b/app/controllers/shop/registrations_controller.rb @@ -2,15 +2,10 @@ class Shop::RegistrationsController < Shop::AppController prepend_before_filter :require_no_authentication, :only => [ :new, :create, :cancel ] skip_before_filter :must_has_theme - include Devise::Controllers::InternalHelpers include Shop::OrderHelper - #layout 'shop/admin' expose(:shop) { Shop.at(request.host) } - - # GET /resource/sign_up def new - resource = build_resource({}) path = Rails.root.join 'app/views/shop/templates/customers/registrations.liquid' assign = template_assign('template' => 'customers') liquid_view = Liquid::Template.parse(File.read(path)).render(assign) @@ -19,15 +14,12 @@ def new render text: html end - # POST /resource def create - build_resource - resource.shop = shop + resource = shop.customers.build params[:customer] if resource.save if resource.active_for_authentication? - set_flash_message :notice, :signed_up if is_navigational_format? - sign_in(resource_name, resource) + sign_in(resource) if checkout_url # 跳转到结算页面 token = checkout_url.gsub(/.+\//,'') if cart = Cart.find_by_token(token) diff --git a/app/controllers/shop/sessions_controller.rb b/app/controllers/shop/sessions_controller.rb index c6a5057f..bbde52b0 100644 --- a/app/controllers/shop/sessions_controller.rb +++ b/app/controllers/shop/sessions_controller.rb @@ -5,19 +5,13 @@ # a. 登录或注册后返回 # b. 不登录,以游客身份返回 class Shop::SessionsController < Shop::AppController - #prepend_before_filter :require_no_authentication, :only => [:new, :create ] #去掉此句,以便用户能更改账号付账 - #before_filter :get_host, only: :create - include Devise::Controllers::InternalHelpers include Shop::OrderHelper skip_before_filter :must_has_theme - prepend_before_filter :allow_params_authentication!, only: :create - #layout 'shop/admin' + prepend_before_filter :allow_params_authentication!, only: :create # allow devise authen from post params + # respond_to :html # use for create action respond_with expose(:shop) { Shop.at(request.host) } - # GET /resource/sign_in def new - resource = build_resource - clean_up_passwords(resource) path = theme.template_path('customers/login') path = Rails.root.join 'app/views/shop/templates/customers/login.liquid' unless File.exist?(path) assign = template_assign('template' => 'customers_login', 'errors' => flash[:alert], 'recover_errors' => flash[:notice]) @@ -27,9 +21,8 @@ def new render text: html end - # POST /resource/sign_in def create - env['warden'].logout(resource_name) #点换用户时,先清空以前session中的用户,由于warden的方法,会先从sessio中找已经存在的用户 + #env['warden'].logout(resource_name) #点换用户时,先清空以前session中的用户,由于warden的方法,会先从sessio中找已经存在的用户 if params[:guest].present? and checkout_url.present? token = checkout_url.gsub(/.+\//,'') if cart = Cart.find_by_token(token) @@ -38,46 +31,24 @@ def create end redirect_to checkout_url and return end - resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new") - set_flash_message(:notice, :signed_in) if is_navigational_format? - sign_in(resource_name, resource) + customer = warden.authenticate!(scope: :customer, recall: "#{controller_path}#new") # redirect_to new action if auth fail + sign_in customer if checkout_url #用于增加购物车与顾客之间的关联 token = checkout_url.gsub(/.+\//,'') if cart = Cart.find_by_token(token) and !params[:guest].present? - cart.customer = resource + cart.customer = customer cart.save! end redirect_to checkout_url and return else - respond_with resource, location: after_sign_in_path_for(resource) + # respond_with customer, location: after_sign_in_path_for(customer) + redirect_to after_sign_in_path_for(customer) end end - # GET /resource/sign_out def destroy - signed_in = signed_in?(resource_name) - Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name) - set_flash_message :notice, :signed_out if signed_in - - # We actually need to hardcode this, as Rails default responder doesn't - # support returning empty response on GET request - respond_to do |format| - format.any(*navigational_formats) { redirect_to after_sign_out_path_for(resource_name) } - format.all do - method = "to_#{request_format}" - text = {}.respond_to?(method) ? {}.send(method) : "" - render :text => text, :status => :ok - end - end - end - - protected - - def stub_options(resource) - methods = resource_class.authentication_keys.dup - methods = methods.keys if methods.is_a?(Hash) - methods << :password if resource.respond_to?(:password) - { :methods => methods, :only => [:password] } + sign_out(:customer) + redirect_to after_sign_out_path_for(:customer) end end diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 8d7c5cb8..15794adb 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -179,5 +179,6 @@ #config.warden do |manager| # manager.failure_app = CustomFailure #end - #config.reset_password_within = 0.days + + config.reset_password_within = 1.days end diff --git a/config/routes.rb b/config/routes.rb index 0af6fba4..cbbb026d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,7 +16,7 @@ end constraints(Domain::Wiki) do # 帮助文档 - devise_scope :admin_users, ActiveAdmin::Devise.config + devise_for :admin_users, ActiveAdmin::Devise.config scope module: :wiki do get '/' , to: 'wiki_pages#index' , as: :wiki_pages_index get '/active_admin' , to: redirect('/') @@ -84,6 +84,8 @@ get '/login' , to: 'home#login' scope "/services/signup" do get '/' , to: 'home#signup' , as: :services_signup + # :confirmations, :omniauth_callbacks, :passwords, :registrations, :sessions, :unlocks + devise_for :user, skip: [:sessions, :confirmations, :passwords], skip_helpers: true devise_scope :user do get "/new/:plan" , to: "registrations#new" , as: :signup get "/check_availability", to: "registrations#check_availability" @@ -100,15 +102,16 @@ mount Resque::Server.new, at: "/resque" # 查看后台任务执行情况 end - devise_scope :admin_users, ActiveAdmin::Devise.config + devise_for :admin_users, ActiveAdmin::Devise.config end constraints(Domain::Store) do - devise_scope :user, skip: :registrations, controllers: {sessions: "admin/sessions"}# 登录 + devise_for :user, skip: :registrations, controllers: {sessions: "admin/sessions"} # 登录 scope module: :shop do # 前台商店 scope '/account' do + devise_for :customer, skip: :all, skip_helpers: true devise_scope :customer do get '/login' , to: 'sessions#new' post '/login' , to: 'sessions#create' From bb17d50d1ea8c80931c3770d3ba1dfb1fe154cf7 Mon Sep 17 00:00:00 2001 From: saberma Date: Tue, 31 Jul 2012 10:51:15 +0800 Subject: [PATCH 09/35] refactory passwords controller. --- app/controllers/shop/passwords_controller.rb | 45 ++++----- .../shop/registrations_controller.rb | 96 +++---------------- config/routes.rb | 2 +- 3 files changed, 33 insertions(+), 110 deletions(-) diff --git a/app/controllers/shop/passwords_controller.rb b/app/controllers/shop/passwords_controller.rb index 51acf6be..82a2a11a 100644 --- a/app/controllers/shop/passwords_controller.rb +++ b/app/controllers/shop/passwords_controller.rb @@ -1,36 +1,31 @@ #encoding: utf-8 class Shop::PasswordsController < Shop::AppController - prepend_before_filter :require_no_authentication skip_before_filter :must_has_theme expose(:shop) { Shop.at(request.host) } - # GET /resource/password/new - def new - build_resource({}) - render_with_scope :new - end + # new action is not need, it's contained in login page, show by js click. # POST /resource/password def create - self.resource = resource_class.send_reset_password_instructions(email: params[:email]) + @customer = Customer.send_reset_password_instructions(email: params[:email]) - if successful_and_sane?(resource) - set_flash_message(:notice, :send_instructions) if is_navigational_format? - respond_with({}, :location => after_sending_reset_password_instructions_path_for(resource_name)) + if successfully_sent?(@customer) + respond_with({}, location: after_sending_reset_password_instructions_path_for(:customer)) else - #respond_with_navigational(resource){ render_with_scope :new } - flash[:notice] = resource.errors.full_messages + flash[:notice] = @customer.errors.full_messages redirect_to '/account/login#recover' end end # GET /resource/password/edit?reset_password_token=abcdef def edit - self.resource = resource_class.new - resource.reset_password_token = params[:reset_password_token] + unless @customer # from update action + @customer = shop.customers.build + @customer.reset_password_token = params[:reset_password_token] + end path = theme.template_path('customers/reset_password') path = Rails.root.join 'app/views/shop/templates/customers/reset_password.liquid' unless File.exist?(path) - assign = template_assign('template' => 'customers_reset_password', 'customer' => CustomerDrop.new(resource)) + assign = template_assign('template' => 'customers_reset_password', 'customer' => CustomerDrop.new(@customer)) liquid_view = Liquid::Template.parse(File.read(path)).render(assign) assign.merge!('content_for_layout' => liquid_view) html = Liquid::Template.parse(layout_content).render(shop_assign(assign)) @@ -39,21 +34,15 @@ def edit # PUT /resource/password def update - self.resource = resource_class.reset_password_by_token(params[resource_name]) + @customer = Customer.reset_password_by_token(params[:customer]) - if resource.errors.empty? - flash_message = resource.active_for_authentication? ? :updated : :updated_not_active - set_flash_message(:notice, flash_message) if is_navigational_format? - sign_in(resource_name, resource) - respond_with resource, location: after_sign_in_path_for(resource) + if @customer.errors.empty? + flash_message = @customer.active_for_authentication? ? :updated : :updated_not_active + set_flash_message(:notice, flash_message) + sign_in(:customer, @customer) + respond_with @customer, location: after_sign_in_path_for(@customer) else - path = theme.template_path('customers/reset_password') - path = Rails.root.join 'app/views/shop/templates/customers/reset_password.liquid' unless File.exist?(path) - assign = template_assign('template' => 'customers_reset_password', 'customer' => CustomerDrop.new(resource)) - liquid_view = Liquid::Template.parse(File.read(path)).render(assign.merge!('reset_password_token' => resource.reset_password_token )) - assign.merge!('content_for_layout' => liquid_view) - html = Liquid::Template.parse(layout_content).render(shop_assign(assign)) - render text: html + edit end end diff --git a/app/controllers/shop/registrations_controller.rb b/app/controllers/shop/registrations_controller.rb index 66bdeb15..bd494e96 100644 --- a/app/controllers/shop/registrations_controller.rb +++ b/app/controllers/shop/registrations_controller.rb @@ -1,13 +1,14 @@ #encoding: utf-8 class Shop::RegistrationsController < Shop::AppController - prepend_before_filter :require_no_authentication, :only => [ :new, :create, :cancel ] skip_before_filter :must_has_theme include Shop::OrderHelper expose(:shop) { Shop.at(request.host) } def new path = Rails.root.join 'app/views/shop/templates/customers/registrations.liquid' - assign = template_assign('template' => 'customers') + options = {'template' => 'customers'} + options.merge!('customer' => CustomerDrop.new(customer)) if @customer + assign = template_assign(options) liquid_view = Liquid::Template.parse(File.read(path)).render(assign) assign.merge!('content_for_layout' => liquid_view) html = Liquid::Template.parse(layout_content).render(shop_assign(assign)) @@ -15,89 +16,22 @@ def new end def create - resource = shop.customers.build params[:customer] - - if resource.save - if resource.active_for_authentication? - sign_in(resource) - if checkout_url # 跳转到结算页面 - token = checkout_url.gsub(/.+\//,'') - if cart = Cart.find_by_token(token) - cart.customer = resource - cart.save! - end - redirect_to checkout_url and return - else - respond_with resource, location: after_sign_in_path_for(resource_name, resource) + @customer = shop.customers.build params[:customer] + + if @customer.save + sign_in(@customer) + if checkout_url # 跳转到结算页面 + token = checkout_url.gsub(/.+\//,'') + if cart = Cart.find_by_token(token) + cart.customer = @customer + cart.save! end + redirect_to checkout_url and return else - set_flash_message :notice, :inactive_signed_up, :reason => inactive_reason(resource) if is_navigational_format? - expire_session_data_after_sign_in! - respond_with resource, :location => after_inactive_sign_up_path_for(resource) + redirect_to after_sign_in_path_for(:customer, @customer) and return end else - clean_up_passwords(resource) - path = Rails.root.join 'app/views/shop/templates/customers/registrations.liquid' - assign = template_assign('template' => 'customers', 'customer' => CustomerDrop.new(resource)) - liquid_view = Liquid::Template.parse(File.read(path)).render(assign) - assign.merge!('content_for_layout' => liquid_view) - html = Liquid::Template.parse(layout_content).render(shop_assign(assign)) - render text: html - end - end - - # GET /resource/cancel - # Forces the session data which is usually expired after sign - # in to be expired now. This is useful if the user wants to - # cancel oauth signing in/up in the middle of the process, - # removing all OAuth session data. - def cancel - expire_session_data_after_sign_in! - redirect_to new_registration_path(resource_name) - end - - protected - - # Build a devise resource passing in the session. Useful to move - # temporary session data to the newly created user. - def build_resource(hash=nil) - hash ||= params[resource_name] || {} - self.resource = resource_class.new_with_session(hash, session) - end - - # The path used after sign up. You need to overwrite this method - # in your own RegistrationsController. - def after_sign_up_path_for(resource) - after_sign_in_path_for(resource) - end - - # Returns the inactive reason translated. - def inactive_reason(resource) - reason = resource.inactive_message.to_s - I18n.t("devise.registrations.reasons.#{reason}", :default => reason) - end - - # The path used after sign up for inactive accounts. You need to overwrite - # this method in your own RegistrationsController. - def after_inactive_sign_up_path_for(resource) - root_path - end - - # The default url to be used after updating a resource. You need to overwrite - # this method in your own RegistrationsController. - def after_update_path_for(resource) - if defined?(super) - ActiveSupport::Deprecation.warn "Defining after_update_path_for in ApplicationController " << - "is deprecated. Please add a RegistrationsController to your application and define it there." - super - else - after_sign_in_path_for(resource) + new end end - - # Authenticates the current scope and gets the current resource from the session. - def authenticate_scope! - send(:"authenticate_#{resource_name}!", true) - self.resource = send(:"current_#{resource_name}") - end end diff --git a/config/routes.rb b/config/routes.rb index cbbb026d..4dc27d6f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -111,7 +111,7 @@ scope module: :shop do # 前台商店 scope '/account' do - devise_for :customer, skip: :all, skip_helpers: true + devise_for :customer, only: :passwords devise_scope :customer do get '/login' , to: 'sessions#new' post '/login' , to: 'sessions#create' From 9052539d90fa8912049d2879eca97a98aa7ac363 Mon Sep 17 00:00:00 2001 From: saberma Date: Tue, 31 Jul 2012 12:11:17 +0800 Subject: [PATCH 10/35] fixed customer password controller error. --- app/controllers/shop/app_controller.rb | 3 ++- app/controllers/shop/passwords_controller.rb | 12 ++++++------ config/routes.rb | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/controllers/shop/app_controller.rb b/app/controllers/shop/app_controller.rb index 605670e3..4ebb6d1c 100644 --- a/app/controllers/shop/app_controller.rb +++ b/app/controllers/shop/app_controller.rb @@ -33,7 +33,8 @@ def force_domain return unless shop_domain # 排除checkout页面 primary = shop_domain.shop.primary_domain if primary.force_domain and host != primary.host # 重定向 - redirect_to "#{request.protocol}#{primary.host}#{request.port_string}#{request.path}" and return + query_string = "?#{request.query_string}" if request.query_string + redirect_to "#{request.protocol}#{primary.host}#{request.port_string}#{request.path}#{query_string}" and return end end diff --git a/app/controllers/shop/passwords_controller.rb b/app/controllers/shop/passwords_controller.rb index 82a2a11a..2896f8b2 100644 --- a/app/controllers/shop/passwords_controller.rb +++ b/app/controllers/shop/passwords_controller.rb @@ -9,11 +9,12 @@ class Shop::PasswordsController < Shop::AppController def create @customer = Customer.send_reset_password_instructions(email: params[:email]) - if successfully_sent?(@customer) - respond_with({}, location: after_sending_reset_password_instructions_path_for(:customer)) + if @customer.errors.empty? + flash[:notice] = I18n.t("send_instructions", scope: 'devise.passwords') + redirect_to after_sending_reset_password_instructions_path_for(:customer) and return else flash[:notice] = @customer.errors.full_messages - redirect_to '/account/login#recover' + redirect_to '/account/login#recover' and return end end @@ -37,10 +38,9 @@ def update @customer = Customer.reset_password_by_token(params[:customer]) if @customer.errors.empty? - flash_message = @customer.active_for_authentication? ? :updated : :updated_not_active - set_flash_message(:notice, flash_message) + flash[:notice] = I18n.t("updated", scope: 'devise.passwords') sign_in(:customer, @customer) - respond_with @customer, location: after_sign_in_path_for(@customer) + redirect_to after_sign_in_path_for(@customer) and return else edit end diff --git a/config/routes.rb b/config/routes.rb index 4dc27d6f..59bd2955 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -113,7 +113,7 @@ scope '/account' do devise_for :customer, only: :passwords devise_scope :customer do - get '/login' , to: 'sessions#new' + get '/login' , to: 'sessions#new', as: :new_customer_session post '/login' , to: 'sessions#create' get '/signup' , to: 'registrations#new' get '/logout' , to: 'sessions#destroy' From 6587408ad127bf0d8350bc5a33fc51927c8a1a50 Mon Sep 17 00:00:00 2001 From: saberma Date: Tue, 31 Jul 2012 12:13:11 +0800 Subject: [PATCH 11/35] add new_customer_registration_path route. --- config/routes.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 59bd2955..023cd24c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -113,9 +113,9 @@ scope '/account' do devise_for :customer, only: :passwords devise_scope :customer do - get '/login' , to: 'sessions#new', as: :new_customer_session + get '/login' , to: 'sessions#new', as: :new_customer_session post '/login' , to: 'sessions#create' - get '/signup' , to: 'registrations#new' + get '/signup' , to: 'registrations#new', as: :new_customer_registration get '/logout' , to: 'sessions#destroy' end get '/orders/:token' , to: 'account#show_order' , as: :account_show_order From 54c1dbccc62d54dcc7331de415df1eb95181d35c Mon Sep 17 00:00:00 2001 From: saberma Date: Tue, 31 Jul 2012 14:46:53 +0800 Subject: [PATCH 12/35] fixed create customer account error. --- app/controllers/shop/registrations_controller.rb | 4 ++-- app/controllers/shop/sessions_controller.rb | 2 -- config/routes.rb | 11 ++++++----- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/controllers/shop/registrations_controller.rb b/app/controllers/shop/registrations_controller.rb index bd494e96..b5ad7606 100644 --- a/app/controllers/shop/registrations_controller.rb +++ b/app/controllers/shop/registrations_controller.rb @@ -7,7 +7,7 @@ class Shop::RegistrationsController < Shop::AppController def new path = Rails.root.join 'app/views/shop/templates/customers/registrations.liquid' options = {'template' => 'customers'} - options.merge!('customer' => CustomerDrop.new(customer)) if @customer + options.merge!('customer' => CustomerDrop.new(@customer)) if @customer assign = template_assign(options) liquid_view = Liquid::Template.parse(File.read(path)).render(assign) assign.merge!('content_for_layout' => liquid_view) @@ -28,7 +28,7 @@ def create end redirect_to checkout_url and return else - redirect_to after_sign_in_path_for(:customer, @customer) and return + redirect_to after_sign_in_path_for(@customer) and return end else new diff --git a/app/controllers/shop/sessions_controller.rb b/app/controllers/shop/sessions_controller.rb index bbde52b0..006ca117 100644 --- a/app/controllers/shop/sessions_controller.rb +++ b/app/controllers/shop/sessions_controller.rb @@ -41,7 +41,6 @@ def create end redirect_to checkout_url and return else - # respond_with customer, location: after_sign_in_path_for(customer) redirect_to after_sign_in_path_for(customer) end end @@ -52,4 +51,3 @@ def destroy end end - diff --git a/config/routes.rb b/config/routes.rb index 023cd24c..bd92431f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -113,15 +113,16 @@ scope '/account' do devise_for :customer, only: :passwords devise_scope :customer do - get '/login' , to: 'sessions#new', as: :new_customer_session + get '/login' , to: 'sessions#new' , as: :new_customer_session post '/login' , to: 'sessions#create' - get '/signup' , to: 'registrations#new', as: :new_customer_registration get '/logout' , to: 'sessions#destroy' + get '/signup' , to: 'registrations#new' , as: :new_customer_registration + post '/customer' , to: 'registrations#create' end - get '/orders/:token' , to: 'account#show_order' , as: :account_show_order - get '/index' , to: 'account#index', as: :customer_account_index + get '/orders/:token' , to: 'account#show_order', as: :account_show_order + get '/index' , to: 'account#index' , as: :customer_root get '/' , to: 'account#index' - resources :customer_addresses, path: '/addresses' + resources :customer_addresses , path: '/addresses' end match '/' , to: 'shops#show' match '/password' , to: 'shops#password' From 0302e329a9f88473cd2e73dd51e8f6f9af6ecaed Mon Sep 17 00:00:00 2001 From: saberma Date: Tue, 31 Jul 2012 17:47:41 +0800 Subject: [PATCH 13/35] fixed customer router conflict error. --- config/routes.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index bd92431f..4714dc79 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -113,11 +113,11 @@ scope '/account' do devise_for :customer, only: :passwords devise_scope :customer do - get '/login' , to: 'sessions#new' , as: :new_customer_session + get '/login' , to: 'sessions#new' , as: :new_customer_session post '/login' , to: 'sessions#create' get '/logout' , to: 'sessions#destroy' - get '/signup' , to: 'registrations#new' , as: :new_customer_registration - post '/customer' , to: 'registrations#create' + get '/signup' , to: 'registrations#new' , as: :new_customer_registration + post '/customer' , to: 'registrations#create', as: :customer_registration end get '/orders/:token' , to: 'account#show_order', as: :account_show_order get '/index' , to: 'account#index' , as: :customer_root From e4554d26ba87955730ab05e084f24707145e1018 Mon Sep 17 00:00:00 2001 From: saberma Date: Tue, 31 Jul 2012 17:51:58 +0800 Subject: [PATCH 14/35] upgrade devise to 2.1.2 --- Gemfile | 2 +- Gemfile.lock | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index e70ee54a..45a68725 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,7 @@ gem 'rails', '3.2.6' ##### 实体相关 ##### gem 'pg' -gem 'devise', '~> 2.0.0' +gem 'devise', '~> 2.1.2' gem 'sass-rails' # 放在assets分组会报错 http://j.mp/oj7y6K diff --git a/Gemfile.lock b/Gemfile.lock index ce43cd18..89e4fddc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -159,11 +159,11 @@ GEM database_cleaner (0.6.7) decent_exposure (1.0.1) default_value_for (1.0.5) - devise (2.0.4) + devise (2.1.2) bcrypt-ruby (~> 3.0) - orm_adapter (~> 0.0.3) + orm_adapter (~> 0.1) railties (~> 3.1) - warden (~> 1.1.1) + warden (~> 1.2.1) diff-lcs (1.1.3) doorkeeper (0.4.0) railties (~> 3.1) @@ -271,7 +271,7 @@ GEM oauth2 (0.5.2) faraday (~> 0.7) multi_json (~> 1.0) - orm_adapter (0.0.7) + orm_adapter (0.4.0) pg (0.11.0) polyamorous (0.5.0) activerecord (~> 3.0) @@ -414,7 +414,7 @@ GEM macaddr (~> 1.0) vegas (0.1.8) rack (>= 1.0.0) - warden (1.1.1) + warden (1.2.1) rack (>= 1.0) webmock (1.7.10) addressable (~> 2.2, > 2.2.5) @@ -442,7 +442,7 @@ DEPENDENCIES database_cleaner decent_exposure default_value_for - devise (~> 2.0.0) + devise (~> 2.1.2) doorkeeper (~> 0.4.0) dragonfly (~> 0.9.8) exception_notification From 2ac73dc0afd347855b6a85253d7e079f580ff117 Mon Sep 17 00:00:00 2001 From: saberma Date: Tue, 31 Jul 2012 20:26:40 +0800 Subject: [PATCH 15/35] try use 5 paralles test. --- .travis.yml | 19 ------------------- Rakefile | 22 ++++++---------------- 2 files changed, 6 insertions(+), 35 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8f178b0e..ed6ea581 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,31 +12,12 @@ before_script: sh -e /etc/init.d/xvfb start script: - "cp config/database.yml.example config/database.yml 2>&1" - "cp config/app_secret_config.yml.example config/app_secret_config.yml 2>&1" - #- "bundle exec rake travis:init_db" - "bundle exec rake db:drop db:create db:schema:load --trace 2>&1" - "bundle exec rake travis:parallel" env: - UNIT_TEST=1 # 单元测试1 - UNIT_TEST=2 # 单元测试2 - - UNIT_TEST=3 # 单元测试3 - - UNIT_TEST=4 # 单元测试4 - - UNIT_TEST=5 # 单元测试5 - - UNIT_TEST=6 # 单元测试6 - - UNIT_TEST=7 # 单元测试7 - - UNIT_TEST=8 # 单元测试8 - INTEGRATE_TEST=1 # 集成测试1 - INTEGRATE_TEST=2 # 集成测试2 - INTEGRATE_TEST=3 # 集成测试3 - - INTEGRATE_TEST=4 # 集成测试4 - - INTEGRATE_TEST=5 # 集成测试5 - - INTEGRATE_TEST=6 # 集成测试6 - - INTEGRATE_TEST=7 # 集成测试7 - - INTEGRATE_TEST=8 # 集成测试8 - -#notifications: -# recipients: -# - mahb45@gmail.com - -timeouts: - bundle: 1200 diff --git a/Rakefile b/Rakefile index 07918a6e..fd3dd703 100644 --- a/Rakefile +++ b/Rakefile @@ -12,20 +12,10 @@ end namespace :travis do - desc "Init database" - task :init_db do # 并发时使用不同的数据库,否则偶尔会死锁(deadlock detected) - unit_test = ENV['UNIT_TEST'] - integrate_test = ENV['INTEGRATE_TEST'] - path = Rails.root.join 'config/database.yml' - configs = YAML.load_file(path) - db_name = "#{configs[Rails.env]['database']}_#{unit_test && 'u_'}#{unit_test || integrate_test}" - configs[Rails.env]['database'] = db_name - File.open(path, 'w') {|f| YAML.dump(configs, f) } - end - desc "Run travis in parallel" task :parallel do - parallel_size = 8 + unit_parallel_size = 2 + integrate_parallel_size = 3 unit_test = ENV['UNIT_TEST'] integrate_test = ENV['INTEGRATE_TEST'] all_files = Dir.chdir(Rails.root) { Dir["spec/**/*_spec.rb"]}.sort @@ -34,10 +24,10 @@ namespace :travis do %w(shop/shops_searches_spec.rb lookup_spec.rb).each do |searchable_spec| integrate_files.delete "spec/requests/#{searchable_spec}" # 需要solr才能运行 end - files = if unit_test # 8个并发 - unit_files.in_groups(parallel_size)[unit_test.to_i-1].join(' ') - elsif integrate_test # 8个并发 - integrate_files.in_groups(parallel_size)[integrate_test.to_i-1].join(' ') + files = if unit_test # 2个并发 + unit_files.in_groups(unit_parallel_size)[unit_test.to_i-1].join(' ') + elsif integrate_test # 3个并发 + integrate_files.in_groups(integrate_parallel_size)[integrate_test.to_i-1].join(' ') end cmd = "rspec #{files}" From 77a805f0d72999dc51851438f2f7ba8a51f014cb Mon Sep 17 00:00:00 2001 From: saberma Date: Tue, 31 Jul 2012 20:27:17 +0800 Subject: [PATCH 16/35] remove rails-dev-boost gem. --- Gemfile | 1 - Gemfile.lock | 7 ------- 2 files changed, 8 deletions(-) diff --git a/Gemfile b/Gemfile index 45a68725..b0a5e1fa 100644 --- a/Gemfile +++ b/Gemfile @@ -68,7 +68,6 @@ group :development do gem 'rails3-generators' gem "haml-rails" #gem 'ruby-debug19', platforms: :ruby_19 # To use debugger(add 'debugger' in code, then set autoeval; set autolist in console) - gem 'rails-dev-boost', git: 'git://github.com/thedarkone/rails-dev-boost.git', require: 'rails_development_boost' # 加快开发时的响应速度 gem 'rvm-capistrano', "~> 1.1.0", require: 'capistrano' gem "letter_opener" gem 'guard-livereload' diff --git a/Gemfile.lock b/Gemfile.lock index 89e4fddc..f36456e8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -54,12 +54,6 @@ GIT sanitize (~> 2.0.0) sinatra (~> 1.0) -GIT - remote: git://github.com/thedarkone/rails-dev-boost.git - revision: a995f0a3734ecf36da74dcce32ed2ba74e25c56d - specs: - rails-dev-boost (0.1.1) - GEM remote: http://rubygems.org/ specs: @@ -469,7 +463,6 @@ DEPENDENCIES rabl rack-cache rails (= 3.2.6) - rails-dev-boost! rails3-generators resque! resque-scheduler! From 7a0c68e16c45a56b4586f795745d98bf1d96bb62 Mon Sep 17 00:00:00 2001 From: saberma Date: Tue, 31 Jul 2012 20:57:48 +0800 Subject: [PATCH 17/35] upgrade sunspot_rails to 1.3.3 --- Gemfile | 4 ++-- Gemfile.lock | 18 ++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Gemfile b/Gemfile index b0a5e1fa..6d3096fd 100644 --- a/Gemfile +++ b/Gemfile @@ -16,7 +16,7 @@ gem 'acts_as_list', git: 'git://github.com/saberma/acts_as_list.git' # 支持同 gem 'unicorn' gem 'default_value_for' -gem 'sunspot_rails', "~> 1.3.0.rc6" +gem 'sunspot_rails', '~> 1.3.3' gem 'active_hash' # 用于保存配置型(枚举)记录 gem 'kaminari' # 分页 @@ -76,7 +76,7 @@ end group :development, :test do unless ENV['TRAVIS'] # 特殊处理,去掉在travis-ci中不需要的gem gem "awesome_print", require: 'ap' # 调试 - gem 'sunspot_solr' + gem 'sunspot_solr', '~> 1.3.3' end gem "factory_girl" gem "factory_girl_rails" diff --git a/Gemfile.lock b/Gemfile.lock index f36456e8..d427566d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -167,7 +167,6 @@ GEM addressable (>= 2.1.1) eventmachine (>= 0.12.9) erubis (2.7.0) - escape (0.0.4) eventmachine (0.12.10) exception_notification (2.6.1) actionmailer (>= 3.0.4) @@ -321,7 +320,7 @@ GEM resque_spec (0.7.0) resque (>= 1.15.0) rspec (>= 2.5.0) - rsolr (1.0.2) + rsolr (1.0.8) builder (>= 2.1.2) rspec (2.11.0) rspec-core (~> 2.11.0) @@ -376,14 +375,13 @@ GEM activesupport (~> 3.0) polyamorous (~> 0.5.0) subexec (0.1.0) - sunspot (1.3.0.rc6) - escape (= 0.0.4) + sunspot (1.3.3) pr_geohash (~> 1.0) - rsolr (= 1.0.2) - sunspot_rails (1.3.0.rc6) + rsolr (~> 1.0.7) + sunspot_rails (1.3.3) nokogiri - sunspot (= 1.3.0.rc6) - sunspot_solr (1.3.0.rc6) + sunspot (= 1.3.3) + sunspot_solr (1.3.3) susy (1.0.rc.1) compass (>= 0.12.2.rc.0) sass (>= 3.2.0.alpha.237) @@ -479,8 +477,8 @@ DEPENDENCIES sitemap_generator spork squeel - sunspot_rails (~> 1.3.0.rc6) - sunspot_solr + sunspot_rails (~> 1.3.3) + sunspot_solr (~> 1.3.3) susy (~> 1.0.rc.1) therubyracer timecop From 38dad535882f5c84896ec6770e757ccc2577a2e0 Mon Sep 17 00:00:00 2001 From: saberma Date: Tue, 31 Jul 2012 21:27:02 +0800 Subject: [PATCH 18/35] upgrade oauth2 to 0.8.0 resque to 1.21.0 resque-scheduler to 2.0.0 --- Gemfile | 6 +++--- Gemfile.lock | 54 ++++++++++++++++++++++++---------------------------- 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/Gemfile b/Gemfile index 6d3096fd..284fda24 100644 --- a/Gemfile +++ b/Gemfile @@ -45,8 +45,8 @@ gem "activemerchant" # 支付 gem "activemerchant_patch_for_china", git: "git://github.com/saberma/activemerchant_patch_for_china.git" # 支持多个支付帐户(待完成其他财付通等类型后再send pull request) gem "httparty" #gem "resque" # 后台任务 -gem "resque", git: 'git://github.com/defunkt/resque.git' # 1.19.0之后的版本才支持后台运行 -gem "resque-scheduler", git: 'git://github.com/bvandenbos/resque-scheduler.git' # 最新版本才支持后台运行 +gem "resque", "~> 1.21.0" +gem "resque-scheduler", "~> 2.0.0" gem "chinese_pinyin" # 汉字转拼音 gem "nokogiri" # 解释模板config/settings.html gem "uuid" # 生成36位(或32位)唯一序列号 @@ -54,7 +54,7 @@ gem 'settingslogic' #用于解析一些配置信息 #gem 'rack-perftools_profiler', :require => 'rack/perftools_profiler' gem 'grit', git: 'git://github.com/mojombo/grit.git' # 主题版本控制(每个商店主题都是一个git repository) # 2.4.1版本存在此问题 http://j.mp/uoEKw1 gem 'doorkeeper', '~> 0.4.0' -gem "oauth2", "~> 0.5.2" # 0.6.1 版本依赖 multi_json 1.3,与 rails 3.1.5 冲突,0.6.1 以上版本依赖 rack 1.4,与 resque 依赖 1.3 冲突 +gem "oauth2", "~> 0.8.0" gem 'rabl' # 构造 json api 数据 #gem 'newrelic_rpm' # 性能监控(模板编辑器中的layout/theme.liquid也会被注入script,暂时不使用此gem) gem "jquery-rails" diff --git a/Gemfile.lock b/Gemfile.lock index d427566d..d0189e60 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,22 +1,3 @@ -GIT - remote: git://github.com/bvandenbos/resque-scheduler.git - revision: cbad71432341e0b1c32b280970b3cfd327f66d11 - specs: - resque-scheduler (2.0.0.f) - redis (>= 2.0.1) - resque (>= 1.19.0) - rufus-scheduler - -GIT - remote: git://github.com/defunkt/resque.git - revision: af5a9a8e501c3732100b4ec768f7b2a4ec2aec2e - specs: - resque (1.19.0) - multi_json (~> 1.0) - redis-namespace (~> 1.0.2) - sinatra (>= 0.9.2) - vegas (~> 0.1.2) - GIT remote: git://github.com/mojombo/grit.git revision: 8b5449e559879d74224bce3c9c52b0d17bbc0b4b @@ -204,6 +185,7 @@ GEM hike (1.2.1) httparty (0.7.8) crack (= 0.1.8) + httpauth (0.1) i18n (0.6.0) inherited_resources (1.3.1) has_scope (~> 0.5.0) @@ -214,6 +196,8 @@ GEM thor (~> 0.14) json (1.7.4) json_expressions (0.7.2) + jwt (0.1.5) + multi_json (>= 1.0) kaminari (0.13.0) actionpack (>= 3.0.0) activesupport (>= 3.0.0) @@ -261,9 +245,12 @@ GEM net-ssh-gateway (1.1.0) net-ssh (>= 1.99.1) nokogiri (1.5.2) - oauth2 (0.5.2) - faraday (~> 0.7) + oauth2 (0.8.0) + faraday (~> 0.8) + httpauth (~> 0.1) + jwt (~> 0.1.4) multi_json (~> 1.0) + rack (~> 1.2) orm_adapter (0.4.0) pg (0.11.0) polyamorous (0.5.0) @@ -312,11 +299,20 @@ GEM rdoc (3.12) json (~> 1.4) redcarpet (2.0.1) - redis (2.2.2) - redis-namespace (1.0.3) - redis (< 3.0.0) + redis (3.0.1) + redis-namespace (1.2.0) + redis (~> 3.0.0) responders (0.9.2) railties (~> 3.1) + resque (1.21.0) + multi_json (~> 1.0) + redis-namespace (~> 1.0) + sinatra (>= 0.9.2) + vegas (~> 0.1.2) + resque-scheduler (2.0.0) + redis (>= 2.0.1) + resque (>= 1.20.0) + rufus-scheduler resque_spec (0.7.0) resque (>= 1.15.0) rspec (>= 2.5.0) @@ -339,7 +335,7 @@ GEM blankslate (>= 2.1.2.3) ffi (~> 1.0.7) rubyzip (0.9.9) - rufus-scheduler (2.0.16) + rufus-scheduler (2.0.17) tzinfo (>= 0.3.23) rvm-capistrano (1.1.0) capistrano (>= 2.0.0) @@ -404,7 +400,7 @@ GEM raindrops (~> 0.6) uuid (2.3.4) macaddr (~> 1.0) - vegas (0.1.8) + vegas (0.1.11) rack (>= 1.0.0) warden (1.2.1) rack (>= 1.0) @@ -456,14 +452,14 @@ DEPENDENCIES meta_search (~> 1.1.1) mini_magick nokogiri - oauth2 (~> 0.5.2) + oauth2 (~> 0.8.0) pg rabl rack-cache rails (= 3.2.6) rails3-generators - resque! - resque-scheduler! + resque (~> 1.21.0) + resque-scheduler (~> 2.0.0) resque_spec rspec-rails rubyzip From e79715b4e81016883a69f9c23cef14d9b3587bcf Mon Sep 17 00:00:00 2001 From: saberma Date: Tue, 31 Jul 2012 21:28:55 +0800 Subject: [PATCH 19/35] upgrade rails to 3.2.7 --- Gemfile | 2 +- Gemfile.lock | 52 ++++++++++++++++++++++++++-------------------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Gemfile b/Gemfile index 284fda24..9030dd10 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ #rails new . -d postgresql -T -J source 'http://rubygems.org' -gem 'rails', '3.2.6' +gem 'rails', '3.2.7' ##### 实体相关 ##### gem 'pg' diff --git a/Gemfile.lock b/Gemfile.lock index d0189e60..f4b0cbd6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -39,15 +39,15 @@ GEM remote: http://rubygems.org/ specs: RedCloth (4.2.9) - actionmailer (3.2.6) - actionpack (= 3.2.6) + actionmailer (3.2.7) + actionpack (= 3.2.7) mail (~> 2.4.4) - actionpack (3.2.6) - activemodel (= 3.2.6) - activesupport (= 3.2.6) + actionpack (3.2.7) + activemodel (= 3.2.7) + activesupport (= 3.2.7) builder (~> 3.0.0) erubis (~> 2.7.0) - journey (~> 1.0.1) + journey (~> 1.0.4) rack (~> 1.4.0) rack-cache (~> 1.2) rack-test (~> 0.6.1) @@ -75,18 +75,18 @@ GEM i18n json (>= 1.5.1) money (<= 3.7.1) - activemodel (3.2.6) - activesupport (= 3.2.6) + activemodel (3.2.7) + activesupport (= 3.2.7) builder (~> 3.0.0) - activerecord (3.2.6) - activemodel (= 3.2.6) - activesupport (= 3.2.6) + activerecord (3.2.7) + activemodel (= 3.2.7) + activesupport (= 3.2.7) arel (~> 3.0.2) tzinfo (~> 0.3.29) - activeresource (3.2.6) - activemodel (= 3.2.6) - activesupport (= 3.2.6) - activesupport (3.2.6) + activeresource (3.2.7) + activemodel (= 3.2.7) + activesupport (= 3.2.7) + activesupport (3.2.7) i18n (~> 0.6) multi_json (~> 1.0) addressable (2.2.8) @@ -272,19 +272,19 @@ GEM rack rack-test (0.6.1) rack (>= 1.0) - rails (3.2.6) - actionmailer (= 3.2.6) - actionpack (= 3.2.6) - activerecord (= 3.2.6) - activeresource (= 3.2.6) - activesupport (= 3.2.6) + rails (3.2.7) + actionmailer (= 3.2.7) + actionpack (= 3.2.7) + activerecord (= 3.2.7) + activeresource (= 3.2.7) + activesupport (= 3.2.7) bundler (~> 1.0) - railties (= 3.2.6) + railties (= 3.2.7) rails3-generators (0.17.4) railties (>= 3.0.0) - railties (3.2.6) - actionpack (= 3.2.6) - activesupport (= 3.2.6) + railties (3.2.7) + actionpack (= 3.2.7) + activesupport (= 3.2.7) rack-ssl (~> 1.3.2) rake (>= 0.8.7) rdoc (~> 3.4) @@ -456,7 +456,7 @@ DEPENDENCIES pg rabl rack-cache - rails (= 3.2.6) + rails (= 3.2.7) rails3-generators resque (~> 1.21.0) resque-scheduler (~> 2.0.0) From 2854fe152a8bbe87ab13538d244d8bf92e149857 Mon Sep 17 00:00:00 2001 From: saberma Date: Wed, 1 Aug 2012 10:52:13 +0800 Subject: [PATCH 20/35] fixed error cause by rails 3.2.7 destroy order. --- app/models/product.rb | 17 ++++++++--------- spec/models/product_spec.rb | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/models/product.rb b/app/models/product.rb index 504a313a..2824ffe9 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -56,13 +56,6 @@ def photo(version = :icon) before_save do self.make_valid(shop.products) - # 新增的选项默认值要设置到所有款式中 - self.options.reject{|option| option.marked_for_destruction?}.each_with_index do |option, index| - next if option.value.blank? - self.variants.each do |variant| - variant.send "option#{index+1}=", option.value - end - end end def tags_text @@ -214,13 +207,19 @@ class ProductOption < ActiveRecord::Base # 商品选项 attr_accessible :name, :value, :position attr_accessor :value, :first, :last # 辅助值,用于保存至商品款式中 + before_create do # 新增的选项默认值要设置到所有款式中 + product.variants.each do |variant| + variant.update_column "option#{position}", value + end if value.present? + end + before_destroy do # 更新商品所有款式 options_size = product.options.size product.variants.each do |variant| (position...options_size).each do |i| - variant.send("option#{i}=", variant.send("option#{i+1}")) + variant.update_column "option#{i}", variant.send("option#{i+1}") end - variant.save + variant.update_column "option#{options_size}", nil end end diff --git a/spec/models/product_spec.rb b/spec/models/product_spec.rb index 85d56d7d..69c37550 100644 --- a/spec/models/product_spec.rb +++ b/spec/models/product_spec.rb @@ -270,7 +270,7 @@ {name: '大小', value: '默认大小'} ] iphone4.save - iphone4.variants.first.option2.should eql '默认大小' + iphone4.variants.first.reload.option2.should eql '默认大小' end it 'should be destroy' do From 16796d7b75063871e290e5b9007847ca3dd31913 Mon Sep 17 00:00:00 2001 From: saberma Date: Wed, 1 Aug 2012 11:05:00 +0800 Subject: [PATCH 21/35] change parallel size. --- .travis.yml | 2 +- Rakefile | 29 ----------------------------- lib/tasks/travis.rake | 28 ++++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 30 deletions(-) create mode 100644 lib/tasks/travis.rake diff --git a/.travis.yml b/.travis.yml index fccfe0c8..db313af0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ script: env: - UNIT_TEST=1 # 单元测试1 - - UNIT_TEST=2 # 单元测试2 - INTEGRATE_TEST=1 # 集成测试1 - INTEGRATE_TEST=2 # 集成测试2 - INTEGRATE_TEST=3 # 集成测试3 + - INTEGRATE_TEST=4 # 集成测试4 diff --git a/Rakefile b/Rakefile index fd3dd703..e440a1b1 100644 --- a/Rakefile +++ b/Rakefile @@ -10,33 +10,4 @@ task "resque:setup" => :environment do Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection } # 第二次执行resque任务时失败 PGError: ERROR: prepared statement "a3" already exists 参考 http://j.mp/rpVqhc http://j.mp/rqj9CQ ;Rails已经打了补丁,未发布版本 http://j.mp/ntPQMr end -namespace :travis do - - desc "Run travis in parallel" - task :parallel do - unit_parallel_size = 2 - integrate_parallel_size = 3 - unit_test = ENV['UNIT_TEST'] - integrate_test = ENV['INTEGRATE_TEST'] - all_files = Dir.chdir(Rails.root) { Dir["spec/**/*_spec.rb"]}.sort - integrate_files = Dir.chdir(Rails.root) { Dir["spec/requests/**/*_spec.rb"]}.sort - unit_files = all_files - integrate_files - %w(shop/shops_searches_spec.rb lookup_spec.rb).each do |searchable_spec| - integrate_files.delete "spec/requests/#{searchable_spec}" # 需要solr才能运行 - end - files = if unit_test # 2个并发 - unit_files.in_groups(unit_parallel_size)[unit_test.to_i-1].join(' ') - elsif integrate_test # 3个并发 - integrate_files.in_groups(integrate_parallel_size)[integrate_test.to_i-1].join(' ') - end - - cmd = "rspec #{files}" - #cmd = "rspec spec/requests/shop/shop_orders_spec.rb spec/requests/shop/shop_customers_spec.rb" # selenium-webdriver 2.14未清空session,按此顺序运行,第二个用例失败 - puts "Starting to run #{cmd}..." - system("export DISPLAY=:99.0 && bundle exec #{cmd}") - raise "#{cmd} failed!" unless $?.exitstatus == 0 - end - -end - Shopqi::Application.load_tasks diff --git a/lib/tasks/travis.rake b/lib/tasks/travis.rake new file mode 100644 index 00000000..ebd5e4b4 --- /dev/null +++ b/lib/tasks/travis.rake @@ -0,0 +1,28 @@ +namespace :travis do + + desc "Run travis in parallel" + task :parallel do + unit_parallel_size = 1 + integrate_parallel_size = 4 + unit_test = ENV['UNIT_TEST'] + integrate_test = ENV['INTEGRATE_TEST'] + all_files = Dir.chdir(Rails.root) { Dir["spec/**/*_spec.rb"]}.sort + integrate_files = Dir.chdir(Rails.root) { Dir["spec/requests/**/*_spec.rb"]}.sort + unit_files = all_files - integrate_files + %w(shop/shops_searches_spec.rb lookup_spec.rb).each do |searchable_spec| + integrate_files.delete "spec/requests/#{searchable_spec}" # 需要solr才能运行 + end + files = if unit_test # 1个并发 + unit_files.in_groups(unit_parallel_size)[unit_test.to_i-1].join(' ') + elsif integrate_test # 4个并发 + integrate_files.in_groups(integrate_parallel_size)[integrate_test.to_i-1].join(' ') + end + + cmd = "rspec #{files}" + #cmd = "rspec spec/requests/shop/shop_orders_spec.rb spec/requests/shop/shop_customers_spec.rb" # selenium-webdriver 2.14未清空session,按此顺序运行,第二个用例失败 + puts "Starting to run #{cmd}..." + system("export DISPLAY=:99.0 && bundle exec #{cmd}") + raise "#{cmd} failed!" unless $?.exitstatus == 0 + end + +end From ea592a146ad8b5837e4b0acf519237532a8fa672 Mon Sep 17 00:00:00 2001 From: saberma Date: Wed, 1 Aug 2012 11:30:27 +0800 Subject: [PATCH 22/35] remove deprecated update_attribute method. --- app/admin/shops.rb | 2 +- app/controllers/admin/account_controller.rb | 2 +- .../admin/custom_collection_products_controller.rb | 4 ++-- app/controllers/admin/custom_collections_controller.rb | 2 +- app/controllers/admin/links_controller.rb | 2 +- app/controllers/admin/orders_controller.rb | 9 ++++++--- app/controllers/admin/product_variants_controller.rb | 4 ++-- app/controllers/admin/products_controller.rb | 2 +- app/controllers/admin/smart_collections_controller.rb | 4 ++-- app/models/order.rb | 10 ++++++---- app/models/smart_collection.rb | 2 +- app/models/translation.rb | 4 ++-- 12 files changed, 26 insertions(+), 21 deletions(-) diff --git a/app/admin/shops.rb b/app/admin/shops.rb index 26d64f5d..89dc9b43 100644 --- a/app/admin/shops.rb +++ b/app/admin/shops.rb @@ -33,7 +33,7 @@ member_action :restore, method: :put do shop = Shop.find(params[:id]) - shop.update_attribute(:access_enabled,true) + shop.update_attributes access_enabled: true Resque.remove_delayed(DeleteShop, shop.id) redirect_to active_admin_shop_path(shop), notice: '商店已恢复' end diff --git a/app/controllers/admin/account_controller.rb b/app/controllers/admin/account_controller.rb index 993720d9..83c398e3 100644 --- a/app/controllers/admin/account_controller.rb +++ b/app/controllers/admin/account_controller.rb @@ -93,7 +93,7 @@ def destroy if shop.phone && !development? && !test? SMS.safe_send phone, content, request.remote_ip #给商店拥有者发送短信 end - shop.update_attribute(:access_enabled,false) + shop.update_attributes access_enabled: false Resque.enqueue_in(90.days, DeleteShop, shop.id) flash[:alert] = "您的商店已成功删除!" redirect_to home_message_path diff --git a/app/controllers/admin/custom_collection_products_controller.rb b/app/controllers/admin/custom_collection_products_controller.rb index 62c62021..34f6dce1 100644 --- a/app/controllers/admin/custom_collection_products_controller.rb +++ b/app/controllers/admin/custom_collection_products_controller.rb @@ -20,9 +20,9 @@ def destroy #手动调整排序 def sort - custom_collection.update_attribute :products_order, :manual + custom_collection.update_attributes products_order: :manual params[:product].each_with_index do |id, index| - custom_collection.collection_products.find(id).update_attribute :position, index + custom_collection.collection_products.find(id).update_attributes position: index end render :nothing => true end diff --git a/app/controllers/admin/custom_collections_controller.rb b/app/controllers/admin/custom_collections_controller.rb index 1a718424..75632b24 100644 --- a/app/controllers/admin/custom_collections_controller.rb +++ b/app/controllers/admin/custom_collections_controller.rb @@ -46,7 +46,7 @@ def update_order CustomCollection.transaction do custom_collection.save @collection_products = custom_collection.ordered_products.each_with_index do |custom_collection_product, index| - custom_collection_product.update_attribute :position, index + custom_collection_product.update_attributes position: index end end flash.now[:notice] = '重新排序成功!' diff --git a/app/controllers/admin/links_controller.rb b/app/controllers/admin/links_controller.rb index 19dfd945..074ebda4 100644 --- a/app/controllers/admin/links_controller.rb +++ b/app/controllers/admin/links_controller.rb @@ -20,7 +20,7 @@ def destroy def sort params[:link].each_with_index do |id, index| - link_list.links.find(id).update_attribute :position, index + 1 + link_list.links.find(id).update_attributes position: index + 1 end render nothing: true end diff --git a/app/controllers/admin/orders_controller.rb b/app/controllers/admin/orders_controller.rb index d49f8f2d..85ab347d 100644 --- a/app/controllers/admin/orders_controller.rb +++ b/app/controllers/admin/orders_controller.rb @@ -64,7 +64,8 @@ def set value = (operation == :close) ? :closed : :open Order.transaction do shop.orders.find(ids).each do |order| - order.update_attribute :status, value + order.status = value + order.save end end else #支付授权 @@ -77,12 +78,14 @@ def update end def close - order.update_attribute :status, :closed + order.status = :closed + order.save redirect_to orders_path end def open - order.update_attribute :status, :open + order.status = :open + order.save redirect_to order_path(order) end diff --git a/app/controllers/admin/product_variants_controller.rb b/app/controllers/admin/product_variants_controller.rb index b3609235..de31b45b 100644 --- a/app/controllers/admin/product_variants_controller.rb +++ b/app/controllers/admin/product_variants_controller.rb @@ -33,7 +33,7 @@ def set product_variants.find(ids).map(&:destroy) elsif [:price, :inventory_quantity].include?(operation.to_sym) product_variants.find(ids).each do |variant| - variant.update_attribute operation, params[:new_value] + variant.update_attributes operation => params[:new_value] end end end @@ -42,7 +42,7 @@ def set def sort params[:variant].each_with_index do |id, index| - product.variants.find(id).update_attribute :position, index + 1 + product.variants.find(id).update_attributes position: index + 1 end render nothing: true end diff --git a/app/controllers/admin/products_controller.rb b/app/controllers/admin/products_controller.rb index e0b5db60..823cd4a0 100644 --- a/app/controllers/admin/products_controller.rb +++ b/app/controllers/admin/products_controller.rb @@ -105,7 +105,7 @@ def duplicate new_product.options = product.options.map(&:dup).each{|o| o.position = nil } # Fixed: #159 position不为空导致排序报错 new_product.collection_products = product.collection_products.map(&:dup) new_product.tags_text = product.tags_text - new_product.update_attribute :title, params[:new_title] + new_product.update_attributes title: params[:new_title] render json: {id: new_product.id} end diff --git a/app/controllers/admin/smart_collections_controller.rb b/app/controllers/admin/smart_collections_controller.rb index 469c5956..8656ca17 100644 --- a/app/controllers/admin/smart_collections_controller.rb +++ b/app/controllers/admin/smart_collections_controller.rb @@ -51,9 +51,9 @@ def update_order #手动调整排序 def sort - smart_collection.update_attribute :products_order, :manual + smart_collection.update_attributes products_order: :manual params[:product].each_with_index do |id, index| - smart_collection.collection_products.find(id).update_attribute :position, index + smart_collection.collection_products.find(id).update_attributes position: index end render :nothing => true end diff --git a/app/models/order.rb b/app/models/order.rb index 07203539..497d1eaf 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -139,7 +139,8 @@ def cancelled? def cancel! # 取消订单 self.class.transaction do - self.update_attribute :status, :cancelled + self.status = :cancelled + self.save self.line_items.each do |line_item| # 跟踪库存 variant = line_item.product_variant variant.increment! :inventory_quantity if variant.manage_inventory? @@ -260,7 +261,7 @@ class OrderTransaction < ActiveRecord::Base after_create do amount_sum = self.order.transactions.map(&:amount).sum - self.order.update_attribute :financial_status, :paid if amount_sum >= self.order.total_price + self.order.financial_status = :paid if amount_sum >= self.order.total_price self.order.histories.create body: "我们已经成功接收款项" end end @@ -275,10 +276,11 @@ class OrderFulfillment < ActiveRecord::Base after_create do line_items.each do |line_item| - line_item.update_attribute :fulfilled, true + line_item.fulfilled = true + line_item.save end fulfillment_status = (self.order.line_items.unshipped.size > 0) ? :partial : :fulfilled - self.order.update_attribute :fulfillment_status, fulfillment_status + self.order.fulfillment_status = fulfillment_status self.order.histories.create body: "我们已经将#{line_items.size}个商品发货", url: order_fulfillment_path(self.order, self) Resque.enqueue(ShopqiMailer::Ship, 'ship_confirm', self.id) if self.notify_customer == 'true' #当选中通知顾客时,发送邮件(不管有没有写运货单号) end diff --git a/app/models/smart_collection.rb b/app/models/smart_collection.rb index 25941958..78d54a8f 100644 --- a/app/models/smart_collection.rb +++ b/app/models/smart_collection.rb @@ -27,7 +27,7 @@ class SmartCollection < ActiveRecord::Base end rules_products.each_with_index do |product, index| collection_product = self.collection_products.where(product_id: product).first || self.collection_products.new(product: product) - collection_product.update_attribute :position, index + collection_product.update_attributes position: index end end end diff --git a/app/models/translation.rb b/app/models/translation.rb index ead09ef5..fa48ef9a 100644 --- a/app/models/translation.rb +++ b/app/models/translation.rb @@ -7,10 +7,10 @@ def self.get_value(key) value = value.blank? ? key : value end - def self.update_or_create(key,value) + def self.update_or_create(key, value) translation = self.where(key: key).first translation = if translation - translation.update_attribute :value,value + translation.update_attributes value: value else self.create(key: key, value: value) end From 56f15a57711e0e5654cd36c738b558fef6fd4942 Mon Sep 17 00:00:00 2001 From: saberma Date: Wed, 1 Aug 2012 11:37:49 +0800 Subject: [PATCH 23/35] avoid devise warning message. --- config/initializers/devise.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 15794adb..e3514100 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -76,10 +76,6 @@ # If true, extends the user's remember period when remembered via cookie. config.extend_remember_period = true - # If true, uses the password salt as remember token. This should be turned - # to false if you are not using database authenticatable. - config.use_salt_as_remember_token = true - # ==> Configuration for :validatable # Range for password length. Default is 6..20. # config.password_length = 6..20 From 2043d2872c3f392a7256e4fb76f4e75830c8a0a9 Mon Sep 17 00:00:00 2001 From: saberma Date: Wed, 1 Aug 2012 12:01:36 +0800 Subject: [PATCH 24/35] upgrade carrierwave to 0.6.2 --- Gemfile | 2 +- Gemfile.lock | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 9030dd10..2a127d71 100644 --- a/Gemfile +++ b/Gemfile @@ -24,7 +24,7 @@ gem 'kaminari' # 分页 gem 'dragonfly', ' ~> 0.9.8' gem 'rack-cache', require: 'rack/cache' gem 'liquid','~> 2.3.0' #模板语言 -gem "carrierwave" +gem "carrierwave", '~> 0.6.2' gem 'meta_search', '~> 1.1.1' #查询 gem 'squeel' gem 'seedbank' # 分离出各个环境下的seed diff --git a/Gemfile.lock b/Gemfile.lock index f4b0cbd6..c7ab742b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -110,8 +110,9 @@ GEM rack-test (>= 0.5.4) selenium-webdriver (~> 2.0) xpath (~> 0.1.4) - carrierwave (0.5.7) - activesupport (~> 3.0) + carrierwave (0.6.2) + activemodel (>= 3.2.0) + activesupport (>= 3.2.0) childprocess (0.3.4) ffi (~> 1.0, >= 1.0.6) chinese_pinyin (0.3.0) @@ -422,7 +423,7 @@ DEPENDENCIES acts_as_list! awesome_print capybara (~> 1.1.2) - carrierwave + carrierwave (~> 0.6.2) chinese_pinyin client_side_validations coffee-rails From c1a94d9491428af0747ecd1f4d2d36f049b3fcb6 Mon Sep 17 00:00:00 2001 From: saberma Date: Wed, 1 Aug 2012 12:29:22 +0800 Subject: [PATCH 25/35] add time stat for travis-ci. --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index db313af0..d9a19a83 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ rvm: 1.9.3 # RubyPython::PyObject::FFI (NameError) # https://github.com/travis-ci/travis-ci/issues/557#issuecomment-5919720 -before_install: gem uninstall ffi -a +# before_install: gem uninstall ffi -a # request headless test before_script: sh -e /etc/init.d/xvfb start @@ -12,8 +12,8 @@ before_script: sh -e /etc/init.d/xvfb start script: - "cp config/database.yml.example.postgresql config/database.yml 2>&1" - "cp config/app_secret_config.yml.example config/app_secret_config.yml 2>&1" - - "bundle exec rake db:drop db:create db:schema:load --trace 2>&1" - - "bundle exec rake travis:parallel" + - "time bundle exec rake db:drop db:create db:schema:load --trace 2>&1" + - "time bundle exec rake travis:parallel" env: - UNIT_TEST=1 # 单元测试1 From 527b4b545cc98b2b05d5b216f36cdb5d8c803578 Mon Sep 17 00:00:00 2001 From: saberma Date: Wed, 1 Aug 2012 13:51:12 +0800 Subject: [PATCH 26/35] add missing save. --- app/models/order.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/order.rb b/app/models/order.rb index 497d1eaf..b0c9c8bb 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -281,6 +281,7 @@ class OrderFulfillment < ActiveRecord::Base end fulfillment_status = (self.order.line_items.unshipped.size > 0) ? :partial : :fulfilled self.order.fulfillment_status = fulfillment_status + self.order.save self.order.histories.create body: "我们已经将#{line_items.size}个商品发货", url: order_fulfillment_path(self.order, self) Resque.enqueue(ShopqiMailer::Ship, 'ship_confirm', self.id) if self.notify_customer == 'true' #当选中通知顾客时,发送邮件(不管有没有写运货单号) end From 8fe62b0566f3623d3c960a53e2ae52d6a287b108 Mon Sep 17 00:00:00 2001 From: saberma Date: Wed, 1 Aug 2012 14:16:11 +0800 Subject: [PATCH 27/35] remove deprecated update_attribute method in spec file. --- app/models/order.rb | 5 ++++- spec/controllers/shop/collections_controller_spec.rb | 4 ++-- spec/liquids/collections_drop_spec.rb | 2 +- spec/models/discount_spec.rb | 3 ++- spec/observers/activity_observer_spec.rb | 4 ++-- spec/observers/smart_collection_observer_spec.rb | 2 +- spec/requests/customers_spec.rb | 3 ++- spec/requests/orders_spec.rb | 6 ++++-- 8 files changed, 18 insertions(+), 11 deletions(-) diff --git a/app/models/order.rb b/app/models/order.rb index b0c9c8bb..a491e550 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -261,7 +261,10 @@ class OrderTransaction < ActiveRecord::Base after_create do amount_sum = self.order.transactions.map(&:amount).sum - self.order.financial_status = :paid if amount_sum >= self.order.total_price + if amount_sum >= self.order.total_price + self.order.financial_status = :paid + self.order.save + end self.order.histories.create body: "我们已经成功接收款项" end end diff --git a/spec/controllers/shop/collections_controller_spec.rb b/spec/controllers/shop/collections_controller_spec.rb index bf7b2c64..593831f0 100644 --- a/spec/controllers/shop/collections_controller_spec.rb +++ b/spec/controllers/shop/collections_controller_spec.rb @@ -43,7 +43,7 @@ it "should view the index collections" do smart_collection_low_price - iphone4.update_attribute :published, false + iphone4.update_attributes published: false get 'index' response.should be_success response.body.should have_content('首页商品') @@ -72,7 +72,7 @@ response.body.should have_content('低价商品') get 'show', handle: 'low_price' response.body.should_not have_content("此页面不存在") - smart_collection_low_price.update_attribute :published, false + smart_collection_low_price.update_attributes published: false iphone4 get 'index' response.body.should_not have_content('低价商品') diff --git a/spec/liquids/collections_drop_spec.rb b/spec/liquids/collections_drop_spec.rb index 79aa1c40..a0711a69 100644 --- a/spec/liquids/collections_drop_spec.rb +++ b/spec/liquids/collections_drop_spec.rb @@ -43,7 +43,7 @@ variant = "{% for product in collections.frontpage.products %}{{ product.title }}{% endfor %}" result = "#{iphone4.title}" Liquid::Template.parse(variant).render('collections' => collections_drop).should eql result - iphone4.update_attribute :published,false + iphone4.update_attributes published: false variant = "{% if collections.frontpage.products.size == 0 %}没有商品{% endif %}" result = "没有商品" Liquid::Template.parse(variant).render('collections' => collections_drop).should eql result diff --git a/spec/models/discount_spec.rb b/spec/models/discount_spec.rb index 3ac55e36..0b3f2f9d 100644 --- a/spec/models/discount_spec.rb +++ b/spec/models/discount_spec.rb @@ -26,7 +26,8 @@ let(:discount) do model = shop.discounts.create code: 'coupon123', usage_limit: 1 - model.update_attribute :used_times, 1 + model.used_times = 1 + model.save model end diff --git a/spec/observers/activity_observer_spec.rb b/spec/observers/activity_observer_spec.rb index 2649e6b8..f779f936 100644 --- a/spec/observers/activity_observer_spec.rb +++ b/spec/observers/activity_observer_spec.rb @@ -23,11 +23,11 @@ end.to change(Activity,:count).by(1) expect do - blog.update_attribute 'title', 'bbbbb' + blog.update_attributes title: 'bbbbb' end.to change(Activity,:count).by(1) expect do - article.update_attribute 'title', 'cccc' + article.update_attributes title: 'cccc' end.to change(Activity,:count).by(1) diff --git a/spec/observers/smart_collection_observer_spec.rb b/spec/observers/smart_collection_observer_spec.rb index f60890c3..3563d255 100644 --- a/spec/observers/smart_collection_observer_spec.rb +++ b/spec/observers/smart_collection_observer_spec.rb @@ -19,7 +19,7 @@ it "should be insert" do expect do iphone4 - iphone4.update_attribute :body_html, '' #update will not insert again + iphone4.update_attributes body_html: '' #update will not insert again end.to change(SmartCollectionProduct, :count).by(1) end end diff --git a/spec/requests/customers_spec.rb b/spec/requests/customers_spec.rb index abcd4f50..e5653bd4 100644 --- a/spec/requests/customers_spec.rb +++ b/spec/requests/customers_spec.rb @@ -20,7 +20,8 @@ {product_variant: iphone4_variant, price: 10, quantity: 2}, ] o.save - o.update_attribute :financial_status, :pending # 修改为pending会增加消费金额 + o.financial_status = :pending # 修改为pending会增加消费金额 + o.save o end diff --git a/spec/requests/orders_spec.rb b/spec/requests/orders_spec.rb index b137e8cc..4ac73cda 100644 --- a/spec/requests/orders_spec.rb +++ b/spec/requests/orders_spec.rb @@ -63,7 +63,8 @@ context "#pending" do before :each do - order.update_attribute :financial_status, :pending # 假设顾客已经提交订单 + order.financial_status = :pending # 假设顾客已经提交订单 + order.save end it "should save fulfillment" do #支持分批发货 @@ -226,7 +227,8 @@ click_on '放弃' has_content?(order.name).should be_true - order.update_attribute :financial_status, :pending # 假设顾客已经提交订单 + order.financial_status = :pending # 假设顾客已经提交订单 + order.save visit orders_path has_content?(order.name).should be_true end From 84532aa41d59a984e186d4022e64c0a2f35ea2ac Mon Sep 17 00:00:00 2001 From: saberma Date: Wed, 1 Aug 2012 18:37:06 +0800 Subject: [PATCH 28/35] add update variant api. --- .../api/v1/product_variants_controller.rb | 13 ++++ app/views/api/v1/product_variants/show.rabl | 2 + app/views/api/v1/products/index.rabl | 2 +- app/views/api/v1/products/show.rabl | 6 ++ config/routes.rb | 1 + .../v1/product_variants_controller_spec.rb | 70 +++++++++++++++++++ .../api/v1/products_controller_spec.rb | 20 +++++- 7 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 app/controllers/api/v1/product_variants_controller.rb create mode 100644 app/views/api/v1/product_variants/show.rabl create mode 100644 app/views/api/v1/products/show.rabl create mode 100644 spec/controllers/api/v1/product_variants_controller_spec.rb diff --git a/app/controllers/api/v1/product_variants_controller.rb b/app/controllers/api/v1/product_variants_controller.rb new file mode 100644 index 00000000..70f953f7 --- /dev/null +++ b/app/controllers/api/v1/product_variants_controller.rb @@ -0,0 +1,13 @@ +# encoding: utf-8 +module Api::V1 + class ProductVariantsController < AppController + doorkeeper_for :update, scopes: [:write_products], unless: lambda { @api_client } + + def update + @variant = shop.variants.find(params[:id]) + @variant.update_attributes params[:variant].except(:id) + render :show + end + + end +end diff --git a/app/views/api/v1/product_variants/show.rabl b/app/views/api/v1/product_variants/show.rabl new file mode 100644 index 00000000..6a7a7b37 --- /dev/null +++ b/app/views/api/v1/product_variants/show.rabl @@ -0,0 +1,2 @@ +object @variant => :variant +attributes :id, :product_id, :price, :compare_at_price, :weight, :sku, :position, :option1, :option2, :option3, :requires_shipping, :inventory_quantity, :inventory_management, :inventory_policy, :created_at, :updated_at diff --git a/app/views/api/v1/products/index.rabl b/app/views/api/v1/products/index.rabl index bdc60c29..781e980e 100644 --- a/app/views/api/v1/products/index.rabl +++ b/app/views/api/v1/products/index.rabl @@ -1,2 +1,2 @@ collection @products, root: :products, object_root: false -attributes :id, :title, :body_html, :handle, :product_type, :vendor, :created_at, :updated_at +extends "api/v1/products/show" diff --git a/app/views/api/v1/products/show.rabl b/app/views/api/v1/products/show.rabl new file mode 100644 index 00000000..a09eb4ab --- /dev/null +++ b/app/views/api/v1/products/show.rabl @@ -0,0 +1,6 @@ +object @product +attributes :id, :title, :body_html, :handle, :product_type, :vendor, :created_at, :updated_at + +child :variants => :variants do + extends "api/v1/product_variants/show" +end diff --git a/config/routes.rb b/config/routes.rb index 4714dc79..e986a3bc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,6 +9,7 @@ get '/shop' , to: "shops#show" post '/themes/install', to: 'themes#install' get '/products' , to: "products#index" + put '/variants/:id' , to: "product_variants#update" get '/orders' , to: "orders#index" get '/orders/:id' , to: "orders#show" post '/webhooks' , to: "webhooks#create" diff --git a/spec/controllers/api/v1/product_variants_controller_spec.rb b/spec/controllers/api/v1/product_variants_controller_spec.rb new file mode 100644 index 00000000..8e940ee6 --- /dev/null +++ b/spec/controllers/api/v1/product_variants_controller_spec.rb @@ -0,0 +1,70 @@ +#encoding: utf-8 +require 'spec_helper' + +describe Api::V1::ProductVariantsController do + + let(:shop) { Factory(:user).shop } + + let(:iphone4) { Factory :iphone4, shop: shop } + + let(:variant) { iphone4.variants.first } + + let(:body) { {id: variant.id, price: 45 }} # modify to + + before :each do + request.host = "#{shop.primary_domain.host}" + end + + context '#update' do + + before { [iphone4] } + + let(:application) { Factory :express_application } # OAuth application + + context 'with scopes' do # 资源访问范围匹配 + + let(:token) { Factory :access_token, application: application, resource_owner_id: shop.id, scopes: "write_products" } + + it 'should be success' do + put :update, id: variant.id, variant: body, format: :json, access_token: token.token + response.should be_success + json = JSON(response.body)['variant'] + pattern = { + id: variant.id, + product_id: iphone4.id, + price: 45.0, + compare_at_price: 3500.0, + weight: 2.9, + sku: "APPLE1000", + position: 1, + option1: "默认标题", + option2: nil, + option3: nil, + requires_shipping: true, + inventory_quantity: nil, + inventory_management: nil, + inventory_policy: "deny", + created_at: WILDCARD_MATCHER, + updated_at: WILDCARD_MATCHER + } + json.should match_json_expression(pattern) + end + + end + + context 'without scopes' do # 资源访问范围不匹配 + + let(:token) { Factory :access_token, application: application, resource_owner_id: shop.id } + + it 'should be fail' do # 认证失败 + put :update, id: variant.id, variant: body, format: :json, access_token: token.token + response.should_not be_success + response.status.should eql 401 + end + + end + + + end + +end diff --git a/spec/controllers/api/v1/products_controller_spec.rb b/spec/controllers/api/v1/products_controller_spec.rb index 2cf3c041..25c57f63 100644 --- a/spec/controllers/api/v1/products_controller_spec.rb +++ b/spec/controllers/api/v1/products_controller_spec.rb @@ -40,7 +40,25 @@ product_type: "手机", vendor: "Apple", created_at: WILDCARD_MATCHER, - updated_at: WILDCARD_MATCHER + updated_at: WILDCARD_MATCHER, + variants: [{ + id: 1, + product_id: 1, + price: 3000.0, + compare_at_price: 3500.0, + weight: 2.9, + sku: "APPLE1000", + position: 1, + option1: "默认标题", + option2: nil, + option3: nil, + requires_shipping: true, + inventory_quantity: nil, + inventory_management: nil, + inventory_policy: "deny", + created_at: WILDCARD_MATCHER, + updated_at: WILDCARD_MATCHER + }] } product_json.should match_json_expression(pattern) end From 6d6837944f9927cbfc5f61160909a6488d61161a Mon Sep 17 00:00:00 2001 From: saberma Date: Wed, 1 Aug 2012 19:03:05 +0800 Subject: [PATCH 29/35] avoid warning message: Passing the format in the template name is deprecated. --- app/controllers/admin/app_controller.rb | 2 +- app/controllers/admin/sessions_controller.rb | 2 +- app/controllers/shop/app_controller.rb | 2 +- app/controllers/shop/order_controller.rb | 2 +- app/controllers/shopqi/home_controller.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin/app_controller.rb b/app/controllers/admin/app_controller.rb index 2f58aa7a..89386601 100644 --- a/app/controllers/admin/app_controller.rb +++ b/app/controllers/admin/app_controller.rb @@ -37,7 +37,7 @@ def check_permission def check_shop_access_enabled shop = Shop.at(request.host) if !shop.access_enabled - render template: 'shared/no_shop.html', content_type: "text/html", status: 404, layout: nil + render template: 'shared/no_shop', formats: [:html], content_type: "text/html", status: 404, layout: nil end end diff --git a/app/controllers/admin/sessions_controller.rb b/app/controllers/admin/sessions_controller.rb index 7f6401a7..53b95f88 100644 --- a/app/controllers/admin/sessions_controller.rb +++ b/app/controllers/admin/sessions_controller.rb @@ -9,7 +9,7 @@ class Admin::SessionsController < Devise::SessionsController def check_shop_access_enabled shop = Shop.at(request.host) if !shop.access_enabled - render template: 'shared/no_shop.html', content_type: "text/html", status: 404, layout: nil + render template: 'shared/no_shop', formats: [:html], content_type: "text/html", status: 404, layout: nil end end diff --git a/app/controllers/shop/app_controller.rb b/app/controllers/shop/app_controller.rb index 4ebb6d1c..3f748ff2 100644 --- a/app/controllers/shop/app_controller.rb +++ b/app/controllers/shop/app_controller.rb @@ -17,7 +17,7 @@ class Shop::AppController < ActionController::Base protected def check_shop_access_enabled - render template: 'shared/no_shop.html', content_type: "text/html", status: 404, layout: nil and return unless shop.access_enabled + render template: 'shared/no_shop', formats: [:html], content_type: "text/html", status: 404, layout: nil and return unless shop.access_enabled end def check_shop_avaliable redirect_to controller: :shops, action: :unavailable and return unless shop.available? diff --git a/app/controllers/shop/order_controller.rb b/app/controllers/shop/order_controller.rb index a81d6849..6306e033 100644 --- a/app/controllers/shop/order_controller.rb +++ b/app/controllers/shop/order_controller.rb @@ -83,7 +83,7 @@ def create # 提交订单 end def show - render file: 'public/404.html',layout: false, status: 404 unless order + render file: 'public/404', formats: [:html], layout: false, status: 404 unless order end def shipping_rates # 获取快递记录 diff --git a/app/controllers/shopqi/home_controller.rb b/app/controllers/shopqi/home_controller.rb index fd0c6e5e..b765fe52 100644 --- a/app/controllers/shopqi/home_controller.rb +++ b/app/controllers/shopqi/home_controller.rb @@ -9,7 +9,7 @@ def agreement def no_shop logger.error "#{request.host} does not exist!" - render template: 'shared/no_shop.html', content_type: "text/html", status: 404, layout: nil + render template: 'shared/no_shop', formats: [:html], status: 404, layout: nil end def favicon # 官网图标 From fdef5afa45d6af7267c1f4e0322298bc2dce5380 Mon Sep 17 00:00:00 2001 From: saberma Date: Thu, 2 Aug 2012 21:28:36 +0800 Subject: [PATCH 30/35] quite asset. --- config/environments/development.rb | 1 + config/initializers/logger.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 config/initializers/logger.rb diff --git a/config/environments/development.rb b/config/environments/development.rb index 6f11c30a..84252d3a 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -39,6 +39,7 @@ # Expands the lines which load the assets config.assets.debug = true + config.assets.logger = false # quiet assets end diff --git a/config/initializers/logger.rb b/config/initializers/logger.rb new file mode 100644 index 00000000..02864422 --- /dev/null +++ b/config/initializers/logger.rb @@ -0,0 +1,12 @@ +if development? # quiet assets + Rails::Rack::Logger.class_eval do # https://github.com/rails/rails/issues/4569 + def call_with_quiet_assets(env) + previous_level = Rails.logger.level + Rails.logger.level = Logger::ERROR if env['PATH_INFO'].index("/assets/") == 0 + call_without_quiet_assets(env).tap do + Rails.logger.level = previous_level + end + end + alias_method_chain :call, :quiet_assets + end +end From 5788733e293665315a773952bf29af65b2c247cc Mon Sep 17 00:00:00 2001 From: saberma Date: Thu, 2 Aug 2012 21:29:24 +0800 Subject: [PATCH 31/35] order api should has line items. --- app/views/api/v1/orders/line_items/show.rabl | 4 ++++ app/views/api/v1/orders/show.rabl | 8 +++++--- spec/controllers/api/v1/orders_controller_spec.rb | 11 +++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 app/views/api/v1/orders/line_items/show.rabl diff --git a/app/views/api/v1/orders/line_items/show.rabl b/app/views/api/v1/orders/line_items/show.rabl new file mode 100644 index 00000000..16e7920d --- /dev/null +++ b/app/views/api/v1/orders/line_items/show.rabl @@ -0,0 +1,4 @@ +object @line_item +attributes :id, :product_id, :name, :quantity, :price, :sku, :title +attribute product_variant_id: 'variant_id' +attributes :variant_title, :vendor diff --git a/app/views/api/v1/orders/show.rabl b/app/views/api/v1/orders/show.rabl index f86172a8..1d05c479 100644 --- a/app/views/api/v1/orders/show.rabl +++ b/app/views/api/v1/orders/show.rabl @@ -1,6 +1,10 @@ object @order attributes :id, :name, :note, :number, :subtotal_price, :token, :total_line_items_price, :total_price, :total_weight, :order_number, :financial_status, :financial_status_name, :fulfillment_status, :fulfillment_status_name, :cancel_reason, :cancelled_at, :created_at, :updated_at +child :line_items => :line_items do + extends "api/v1/orders/line_items/show" +end + child :transactions => :transactions do attributes :id end @@ -8,9 +12,7 @@ end child :fulfillments => :fulfillments do attributes :id, :order_id, :tracking_company, :tracking_number, :created_at, :updated_at child :line_items => :line_items do - attributes :id, :product_id, :name, :quantity, :price, :sku, :title - attribute product_variant_id: 'variant_id' - attributes :variant_title, :vendor + extends "api/v1/orders/line_items/show" end end diff --git a/spec/controllers/api/v1/orders_controller_spec.rb b/spec/controllers/api/v1/orders_controller_spec.rb index 4568dbff..7ece001f 100644 --- a/spec/controllers/api/v1/orders_controller_spec.rb +++ b/spec/controllers/api/v1/orders_controller_spec.rb @@ -112,6 +112,17 @@ def asset_json(order_json) cancelled_at: nil, created_at: WILDCARD_MATCHER, updated_at: WILDCARD_MATCHER, + line_items: [{ + id: 1, + product_id: 1, + name: "iphone4", + quantity: 2, + price: 10.0, + sku: "APPLE1000", + title: "iphone4", + variant_id: 1, + variant_title: nil, + vendor: "Apple"}], transactions: [], fulfillments: [{ id: 1, From 7da158b1f949aa66861d0eb55e5b761524267ba0 Mon Sep 17 00:00:00 2001 From: saberma Date: Fri, 3 Aug 2012 00:07:06 +0800 Subject: [PATCH 32/35] fixed rspec error. --- app/observers/webhook_observer.rb | 2 +- spec/models/webhook_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/observers/webhook_observer.rb b/app/observers/webhook_observer.rb index 8dd28d2a..fc80ed94 100644 --- a/app/observers/webhook_observer.rb +++ b/app/observers/webhook_observer.rb @@ -6,7 +6,7 @@ def before_update(order) shop = order.shop if order.fulfillment_status_changed? and order.fulfilled? shop.webhooks.orders_fulfilled.each do |webhook| - options = { body: Rabl::Renderer.json(order, 'orders/show', view_path: 'app/views/api/v1') } + options = { body: Rabl::Renderer.json(order, 'api/v1/orders/show', view_path: 'app/views') } options[:headers] = { X_SHOPQI_EVENT: KeyValues::Webhook::Event::ORDERS_FULFILLED, X_SHOPQI_DOMAIN: shop.shopqi_domain, diff --git a/spec/models/webhook_spec.rb b/spec/models/webhook_spec.rb index 48b0ad31..67791788 100644 --- a/spec/models/webhook_spec.rb +++ b/spec/models/webhook_spec.rb @@ -45,7 +45,7 @@ with_resque do fulfillment end - data = Rabl::Renderer.json(order.reload, 'orders/show', view_path: 'app/views/api/v1') + data = Rabl::Renderer.json(order.reload, 'api/v1/orders/show', view_path: 'app/views') headers = { X_SHOPQI_EVENT: 'orders/fulfilled', X_SHOPQI_DOMAIN: shop.shopqi_domain, From 7a26e14b2b3d1bf153903cb1779dfc4dd21d037f Mon Sep 17 00:00:00 2001 From: saberma Date: Fri, 3 Aug 2012 00:24:01 +0800 Subject: [PATCH 33/35] use time zone today. --- spec/controllers/admin/emails_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/controllers/admin/emails_controller_spec.rb b/spec/controllers/admin/emails_controller_spec.rb index 4c1a46a0..3ddc1a6c 100644 --- a/spec/controllers/admin/emails_controller_spec.rb +++ b/spec/controllers/admin/emails_controller_spec.rb @@ -66,7 +66,7 @@ title.should include '[测试商店] 订单 #9999 , 马海波下单' body.should include '测试商店' body.should include '马海波 新增了订单.' - body.should include "今天(#{Date.today.to_s(:db)}" + body.should include "今天(#{Time.zone.today.to_s(:db)}" body.should include '在线支付-支付宝' body.should include '普通快递' body.should include '广东省 深圳市 南山区 科技园南区6栋311' From 7613933219619579f98ce676e0eba65d924ade3f Mon Sep 17 00:00:00 2001 From: saberma Date: Tue, 7 Aug 2012 22:14:14 +0800 Subject: [PATCH 34/35] fixed install theme error. --- app/controllers/theme/themes_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/theme/themes_controller.rb b/app/controllers/theme/themes_controller.rb index e4c290e4..4698e3d9 100644 --- a/app/controllers/theme/themes_controller.rb +++ b/app/controllers/theme/themes_controller.rb @@ -55,7 +55,7 @@ def download # 确认切换主题 def get_shop # 获取商店信息 access_token = OAuth2::AccessToken.from_hash(client, access_token: token) - oauth2_response = access_token.get('/api/v1/shop') + oauth2_response = access_token.get('/api/shop') result = JSON(oauth2_response.body) if result['error'].blank? session[:shop] = result['shop']['name'] @@ -66,7 +66,7 @@ def get_shop # 获取商店信息 def apply # 切换主题 if request.post? access_token = OAuth2::AccessToken.from_hash(client, access_token: token) - oauth2_response = access_token.post('/api/v1/themes/install', params: { handle: handle, style_handle: style_handle }) + oauth2_response = access_token.post('/api/themes/install', params: { handle: handle, style_handle: style_handle }) @result = JSON(oauth2_response.body) end end From 463c73d824e9bbecbf22bc0b8ff74d00f0aceae2 Mon Sep 17 00:00:00 2001 From: saberma Date: Tue, 7 Aug 2012 23:44:46 +0800 Subject: [PATCH 35/35] update changelog. --- CHANGELOG.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 695fb75b..5f62ece0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,21 @@ +## v0.2.0 / 2012-06-17 (9) + +### 功能(7): + +1. Upgrade to Rails3.2.6[saberma] #461 +2. rake db:seed或者db:seed:development:shop 报错[saberma] #459 +3. 商店支持 WebHook[saberma] #457 +4. 后台管理显示已安装应用[saberma] #456 +5. 商品详情的图片要使用绝对路径[saberma] #453 +6. 用户可以安装应用[saberma] #183 +7. 开发app应用示例[saberma] #114 + +### 缺陷(2): + +1. 后台管理日志未显示操作人名称[saberma] #455 +2. 批量修改库存刷新后不生效[saberma] #454 + + ## v0.1.10 / 2012-04-15 (24) ### 功能(12):