From: YOSHIDA Hiroki Date: Tue, 18 Jun 2013 12:46:44 +0000 (+0900) Subject: Travis: MySQLに対応 X-Git-Url: http://git.osdn.net/view?p=elecoma%2Felecoma.git;a=commitdiff_plain;h=00bdda56ef77f6574b04bfe140877306bffcdd88 Travis: MySQLに対応 --- diff --git a/Gemfile b/Gemfile index 2c9ff34..3abfb7d 100644 --- 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' diff --git a/Gemfile.lock b/Gemfile.lock index b21a1e0..339d195 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/config/database.example.yml.mysql b/config/database.yml.mysql similarity index 77% rename from config/database.example.yml.mysql rename to config/database.yml.mysql index 7c74ac2..c9689b6 100644 --- a/config/database.example.yml.mysql +++ b/config/database.yml.mysql @@ -1,7 +1,7 @@ common: &common - adapter: mysql - username: elecoma - password: elecoma + adapter: mysql2 + username: root + password: host: localhost port: 3306 encoding: utf8 diff --git a/config/initializers/merge_adapter_util.rb b/config/initializers/merge_adapter_util.rb index bbb3f82..606fded 100644 --- a/config/initializers/merge_adapter_util.rb +++ b/config/initializers/merge_adapter_util.rb @@ -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 diff --git a/lib/totalizer.rb b/lib/totalizer.rb index b2f4974..5b407e8 100644 --- a/lib/totalizer.rb +++ b/lib/totalizer.rb @@ -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 diff --git a/spec/controllers/admin/totals_controller_spec.rb b/spec/controllers/admin/totals_controller_spec.rb index 7a88a71..7e4a7f3 100644 --- a/spec/controllers/admin/totals_controller_spec.rb +++ b/spec/controllers/admin/totals_controller_spec.rb @@ -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