|
48 | 48 | end |
49 | 49 | end |
50 | 50 |
|
| 51 | + describe "with_disabled_indexes" do |
| 52 | + it "should call ActiveRecord::Base.connection.indexes for table" do |
| 53 | + expect(ActiveRecord::Base.connection).to receive(:indexes).with('table').and_return([]) |
| 54 | + with_disabled_indexes 'table' do |
| 55 | + end |
| 56 | + end |
| 57 | + |
| 58 | + it "should remove indexes first add indexes then" do |
| 59 | + expect(ActiveRecord::Base.connection).to receive(:indexes).with('table').and_return([]) |
| 60 | + expect(self).to receive(:remove_indexes).with([]).ordered |
| 61 | + expect(self).to receive(:add_indexes).with([]).ordered |
| 62 | + with_disabled_indexes 'table' do |
| 63 | + end |
| 64 | + end |
| 65 | + end |
| 66 | + |
| 67 | + describe "remove_indexes" do |
| 68 | + it "should call ActiveRecord::Base.connection.remove_index for each passed index" do |
| 69 | + indexes = [ |
| 70 | + OpenStruct.new(:table => 'table1', :name => 'index1'), |
| 71 | + OpenStruct.new(:table => 'table2', :name => 'index2') |
| 72 | + ] |
| 73 | + expect(ActiveRecord::Base.connection).to receive(:remove_index).with('table1', { :name => 'index1' }).ordered |
| 74 | + expect(ActiveRecord::Base.connection).to receive(:remove_index).with('table2', { :name => 'index2' }).ordered |
| 75 | + remove_indexes indexes |
| 76 | + end |
| 77 | + end |
| 78 | + |
| 79 | + describe "index_options" do |
| 80 | + it "should return non-empty valid index options" do |
| 81 | + index = OpenStruct.new( |
| 82 | + :unique => nil, |
| 83 | + :name => 'index1', |
| 84 | + :unknown_key => 1, |
| 85 | + |
| 86 | + :members => [:unique, :order, :name, :where, :length, :internal, :using, :algorithm, :type] |
| 87 | + ) |
| 88 | + expect(index_options(index)).to eq(:name => 'index1') |
| 89 | + end |
| 90 | + end |
| 91 | + |
| 92 | + describe "add_indexes" do |
| 93 | + it "should call ActiveRecord::Base.connection.add_index for each passed index" do |
| 94 | + indexes = [ |
| 95 | + OpenStruct.new(:table => 'table1', :columns => [:column1], :name => 'index1', :unknown_key => 1, :members => [:name]), |
| 96 | + OpenStruct.new(:table => 'table2', :columns => [:column2], :name => 'index2', :unknown_key => 1, :members => [:name]) |
| 97 | + ] |
| 98 | + expect(ActiveRecord::Base.connection).to receive(:add_index).with('table1', [:column1], { :name => 'index1' }).ordered |
| 99 | + expect(ActiveRecord::Base.connection).to receive(:add_index).with('table2', [:column2], { :name => 'index2' }).ordered |
| 100 | + add_indexes indexes |
| 101 | + end |
| 102 | + end |
| 103 | + |
51 | 104 | describe "insert_into_table" do |
52 | 105 | it "should call ActiveRecord::Base.connection.insert with sql for insert if values is string" do |
53 | 106 | expect(ActiveRecord::Base.connection).to receive(:insert).with("INSERT INTO `table` (`c1`,`c2`) VALUES (`v1`,`v2`)", anything) |
|
0 commit comments