OSDN Git Service

Travis: MySQLに対応
authorYOSHIDA Hiroki <hyoshida@appirits.com>
Tue, 18 Jun 2013 12:46:44 +0000 (21:46 +0900)
committerYOSHIDA Hiroki <hyoshida@appirits.com>
Tue, 18 Jun 2013 16:58:05 +0000 (01:58 +0900)
Gemfile
Gemfile.lock
config/database.yml.mysql [moved from config/database.example.yml.mysql with 77% similarity]
config/initializers/merge_adapter_util.rb
lib/totalizer.rb
spec/controllers/admin/totals_controller_spec.rb

diff --git a/Gemfile b/Gemfile
index 2c9ff34..3abfb7d 100644 (file)
--- a/Gemfile
+++ b/Gemfile
@@ -6,6 +6,7 @@ gem "tzinfo", "~> 0.3.31"
 
 # Supported DBs
 gem "pg", :group => :postgresql
+gem "activerecord-mysql2-adapter", :group => :mysql
 
 gem 'rake', '~> 10.0'
 gem 'test-unit', '1.2.3'
index b21a1e0..339d195 100644 (file)
@@ -22,6 +22,8 @@ GEM
       rack (~> 1.1.0)
     activerecord (2.3.17)
       activesupport (= 2.3.17)
+    activerecord-mysql2-adapter (0.0.3)
+      mysql2
     activeresource (2.3.17)
       activesupport (= 2.3.17)
     activesupport (2.3.17)
@@ -51,6 +53,7 @@ GEM
     locale (2.0.8)
     method_source (0.8.1)
     moji (1.6)
+    mysql2 (0.3.11)
     pdf-reader (1.3.3)
       Ascii85 (~> 1.0.0)
       afm (~> 0.2.0)
@@ -102,6 +105,7 @@ PLATFORMS
   ruby
 
 DEPENDENCIES
+  activerecord-mysql2-adapter
   acts_as_list!
   acts_as_tree (= 0.1.1)
   ar_fixtures
similarity index 77%
rename from config/database.example.yml.mysql
rename to config/database.yml.mysql
index 7c74ac2..c9689b6 100644 (file)
@@ -1,7 +1,7 @@
 common: &common
-  adapter: mysql
-  username: elecoma
-  password: elecoma
+  adapter: mysql2
+  username: root
+  password:
   host: localhost
   port: 3306
   encoding: utf8
index bbb3f82..606fded 100644 (file)
@@ -2,54 +2,54 @@
 class MergeAdapterUtil
   def self.convert_time_to_yyyymmdd(column)
     case ActiveRecord::Base.connection.adapter_name
-    when 'PostgreSQL'
+    when /PostgreSQL/i
       "to_char(#{column}, 'YYYYMMDD')"
-    when 'MySQL'
+    when /MySQL/i
       "date_format(#{column}, '%%Y%%m%%d')"
     end
   end
   
   def self.convert_time_to_mm(column)
     case ActiveRecord::Base.connection.adapter_name
-    when 'PostgreSQL'
+    when /PostgreSQL/i
       "to_char(#{column}, 'MM')"
-    when 'MySQL'
+    when /MySQL/i
       "date_format(#{column}, '%%m')"
     end
   end
 
   def self.concat(*columns)
     case ActiveRecord::Base.connection.adapter_name
-    when 'PostgreSQL'
+    when /PostgreSQL/i
       columns.join(' || ')
-    when 'MySQL'
+    when /MySQL/i
       "concat(#{columns.join(',')})"
     end
   end 
 
   def self.age(from, to="now()")
     case ActiveRecord::Base.connection.adapter_name
-    when 'PostgreSQL'
+    when /PostgreSQL/i
       "age(#{to}, #{from})"
-    when 'MySQL'
+    when /MySQL/i
       "from_days(datediff(#{to}, #{from}))"
     end
   end
 
   def self.interval_second(interval_str)
     case ActiveRecord::Base.connection.adapter_name
-    when 'PostgreSQL'
+    when /PostgreSQL/i
       "interval '#{interval_str} seconds'"
-    when 'MySQL'
+    when /MySQL/i
       "interval #{interval_str} second"
     end
   end
 
   def self.day_of_week(column)
     case ActiveRecord::Base.connection.adapter_name
-    when 'PostgreSQL'
+    when /PostgreSQL/i
       "extract(dow from #{column})"
-    when 'MySQL'
+    when /MySQL/i
       "dayofweek(#{column})"
     end
   end    
index b2f4974..5b407e8 100644 (file)
@@ -380,7 +380,7 @@ class ProductTotalizer < Totalizer
     # position の振り直し & 販売開始日を Date に
     records.zip((1..records.size).to_a) do | r, i |
       r.position = i
-      r.sale_start_at = Date.parse(r.sale_start_at)
+      r.sale_start_at = r.sale_start_at.to_date
     end
     records
   end
index 7a88a71..7e4a7f3 100644 (file)
@@ -286,23 +286,18 @@ describe Admin::TotalsController do
     end
 
     it "販売開始期間を指定して集計" do
-      start_from = Date.new(2008, 8, 1)
-      start_to = Date.today
-      search = {
-        'month(1i)'=>start_from.year, 'month(2i)'=>start_from.month, :by_month => 'x',
-        'sale_start_from(1i)' => start_from.year.to_s,
-        'sale_start_from(2i)' => start_from.month.to_s,
-        'sale_start_from(3i)' => start_from.day.to_s,
-        'sale_start_to(1i)' => start_to.year.to_s,
-        'sale_start_to(2i)' => start_to.month.to_s,
-        'sale_start_to(3i)' => start_to.day.to_s
-      }
+      date_from = Date.new(2008, 8, 1)
+      date_to = Date.today
+      search = { :by_month => 'x' }.
+        merge(date_to_select(date_from, 'month')).
+        merge(date_to_select(date_from, 'sale_start_from')).
+        merge(date_to_select(date_to, 'sale_start_to'))
       post 'index', :page => 'product', :type => 'all', :search => search
       assigns[:sale_start_enabled].should be_true
       assigns[:records].should_not be_empty
       assigns[:records].each do | record |
-        record.sale_start_at.should >= start_from
-        record.sale_start_at.should <= start_to
+        record.sale_start_at.should >= date_from
+        record.sale_start_at.should <= date_to
       end
     end
 
@@ -311,7 +306,7 @@ describe Admin::TotalsController do
       date_to = DateTime.new(2008,8,31,23,59,59)
       conds = ['received_at between ? and ? and status in (?)', date_from, date_to,
                [OrderDelivery::HASSOU_TYUU, OrderDelivery::HAITATU_KANRYO]]
-      search = {'by_date'=>'x'}.
+      search = { :by_date => 'x' }.
         merge(date_to_select(date_from, 'date_from')).
         merge(date_to_select(date_to, 'date_to'))
       post 'index', :page => 'product', :type => 'all', :search => search