Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run migration tests only for latest rails. I added also missing index for faster search and upgrade rails version.
- Loading branch information
Showing
11 changed files
with
120 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
lib/generators/acts_as_messageable/migration/templates/migration.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
lib/generators/acts_as_messageable/migration/templates/migration_indexes.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class AddIndexesToMessages < ActiveRecord::Migration[4.2] | ||
def self.up | ||
add_index :<%= table_name %>, [:sent_messageable_id, :sent_messageable_type], :name => "acts_as_messageable_sent" | ||
add_index :<%= table_name %>, [:received_messageable_id, :received_messageable_type], :name => "acts_as_messageable_received" | ||
end | ||
|
||
def self.down | ||
remove_index :<%= table_name %>, :name => "acts_as_messageable_sent" | ||
remove_index :<%= table_name %>, :name => "acts_as_messageable_received" | ||
end | ||
end |
6 changes: 3 additions & 3 deletions
6
lib/generators/acts_as_messageable/migration/templates/migration_opened_as_datetime.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
class AddOpenedAtToMessages < ActiveRecord::Migration | ||
class AddOpenedAtToMessages < ActiveRecord::Migration[4.2] | ||
def self.up | ||
add_column :<%= table_name %>, :opened_at, :datetime | ||
<%= table_name.classify %>.where(opened:true).update_all(opened_at: DateTime.now) | ||
ActsAsMessageable::Message.where(opened: true).update_all(opened_at: DateTime.now) | ||
end | ||
|
||
def self.down | ||
<%= table_name.classify %>.where.not(opened_at:nil).update_all(opened: true) | ||
ActsAsMessageable::Message.where('opened_at is not null').update_all(opened: true) | ||
remove_column :<%= table_name %>, :opened_at | ||
end | ||
end |
2 changes: 1 addition & 1 deletion
2
lib/generators/acts_as_messageable/migration/templates/migration_permanent.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
def create_dummy_app | ||
system <<-COMMAND | ||
bundle exec rails new dummy --skip-test-unit --skip-spring --skip-webpack-install --skip-bootsnap \ | ||
--skip-active-storage --skip-active-job -d sqlite3 | ||
COMMAND | ||
end | ||
|
||
def add_gem_to_gemfile | ||
run_in_app("echo gem \"'acts-as-messageable', path: '../'\" >> Gemfile; bundle") | ||
end | ||
|
||
def run_bundler | ||
run_in_app('bundle update') | ||
end | ||
|
||
def run_generators | ||
run_in_app('bundle exec rails g acts_as_messageable:migration') | ||
end | ||
|
||
def run_migrations | ||
run_in_app('bundle exec rake db:migrate') | ||
end | ||
|
||
def rollback_migrations | ||
run_in_app('bundle exec rake db:migrate VERSION=0') | ||
end | ||
|
||
def run_in_app(command) | ||
Bundler.clean_system("cd dummy; BUNDLE_GEMFILE=./Gemfile #{command}") | ||
end | ||
|
||
def remove_dummy_app | ||
system 'rm -rf dummy' | ||
end | ||
|
||
def skip_generators? | ||
ENV.fetch('RUN_GENERATORS', 'false') == 'false' | ||
end | ||
|
||
describe 'migration' do | ||
before do | ||
create_dummy_app | ||
add_gem_to_gemfile | ||
run_bundler | ||
end | ||
|
||
after do | ||
remove_dummy_app | ||
end | ||
|
||
it 'runs migrations and revert them', skip: skip_generators? do | ||
run_generators | ||
|
||
expect(run_migrations).to be_truthy | ||
expect(rollback_migrations).to be_truthy | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,6 @@ class User < ActiveRecord::Base | |
|
||
class Men < User | ||
end | ||
|
||
class CustomSearchUser < ActiveRecord::Base | ||
end |