OSDN Git Service

開発中コードを一旦コミット
authorTaro Matsuzawa <tmatsuzawa@kbmj.com>
Thu, 26 Aug 2010 08:13:56 +0000 (17:13 +0900)
committerTaro Matsuzawa <tmatsuzawa@kbmj.com>
Thu, 26 Aug 2010 08:13:56 +0000 (17:13 +0900)
app/controllers/cart_controller.rb
app/models/normal_payment_plugin.rb [new file with mode: 0644]
app/models/payment.rb
app/models/payment_plugin.rb [new file with mode: 0644]
lib/payment_plugin_base.rb [new file with mode: 0644]
spec/fixtures/payment_plugins.yml [new file with mode: 0644]
spec/models/normal_payment_plugin_spec.rb [new file with mode: 0644]

index 37441c5..c3ec28a 100644 (file)
@@ -453,6 +453,9 @@ class CartController < BaseController
     redirect_to :action => :finish, :ids => ids
   end
 
+  def before_finish
+  end
+
   def finish
     unless flash[:completed]
       render :template => 'cart/405', :status => :method_not_allowed
diff --git a/app/models/normal_payment_plugin.rb b/app/models/normal_payment_plugin.rb
new file mode 100644 (file)
index 0000000..d6f6956
--- /dev/null
@@ -0,0 +1,4 @@
+class NormalPaymentPlugin < ActiveForm
+  include PaymentPluginBase
+
+end
index b7900c7..ae248b6 100644 (file)
@@ -7,6 +7,7 @@ class Payment < ActiveRecord::Base
   belongs_to :resource, 
              :class_name => "ImageResource",
              :foreign_key => "resource_id"
+  belongs_to :payment_plugin
   has_many :orders
   
   validates_presence_of :name,:fee,:delivery_trader_id
diff --git a/app/models/payment_plugin.rb b/app/models/payment_plugin.rb
new file mode 100644 (file)
index 0000000..bb132dc
--- /dev/null
@@ -0,0 +1,12 @@
+class PaymentPlugin < ActiveRecord::Base
+  
+  def get_plugin_instance
+    ret = nil
+    class_name = self.model_name.classify
+    if Object.const_defined?(class_name)
+      ret = Object.const_get(class_name).new
+    end
+    return ret
+  end
+
+end
diff --git a/lib/payment_plugin_base.rb b/lib/payment_plugin_base.rb
new file mode 100644 (file)
index 0000000..f5b71e8
--- /dev/null
@@ -0,0 +1,12 @@
+module PaymentPluginBase
+  def confirm
+    return nil
+  end
+
+  def before_finish
+
+  end
+
+  def confirm_method?(method_name)
+  end
+end
diff --git a/spec/fixtures/payment_plugins.yml b/spec/fixtures/payment_plugins.yml
new file mode 100644 (file)
index 0000000..46d2722
--- /dev/null
@@ -0,0 +1,5 @@
+load_normal_plugin:
+  id: 1
+  name: Normal Payment Plugin
+  model_name: NormalPaymentPlugin
+  detail: Normal Payment Plugin Detail
diff --git a/spec/models/normal_payment_plugin_spec.rb b/spec/models/normal_payment_plugin_spec.rb
new file mode 100644 (file)
index 0000000..8e88663
--- /dev/null
@@ -0,0 +1,16 @@
+# -*- coding: utf-8 -*-
+
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe NormalPaymentPlugin do
+  fixtures :payment_plugins
+  
+  it "標準モジュール読み込み" do
+    np = payment_plugins(:load_normal_plugin)
+    np.model_name.classify.should == "NormalPaymentPlugin"
+    instance = np.get_plugin_instance
+    instance.should_not be_nil
+    instance.should be_an_instance_of(NormalPaymentPlugin)
+  end
+end
+