forked from anykeyh/clear
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trying to get the update to work on a secondary connection.
I need a second pair of eyes on this.
- Loading branch information
Showing
7 changed files
with
111 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
require "../spec_helper" | ||
|
||
module MultipleConnectionsSpec | ||
class Post | ||
include Clear::Model | ||
|
||
self.table = "models_posts" | ||
|
||
column id : Int32, primary: true, presence: false | ||
column title : String | ||
end | ||
|
||
class PostStat | ||
include Clear::Model | ||
|
||
self.connection = "secondary" | ||
self.table = "models_post_stats" | ||
|
||
column id : Int32, primary: true, presence: false | ||
column post_id : Int32 | ||
end | ||
|
||
class ModelSpecMigration1234 | ||
include Clear::Migration | ||
|
||
def change(dir) | ||
create_table "models_posts" do |t| | ||
t.string "title", index: true | ||
end | ||
end | ||
end | ||
|
||
def self.reinit | ||
reinit_migration_manager | ||
ModelSpecMigration1234.new.apply(Clear::Migration::Direction::UP) | ||
init_secondary_db | ||
end | ||
|
||
describe "Clear::Model" do | ||
context "multiple connections" do | ||
it "know about the different connections on models" do | ||
Post.connection.should eq "default" | ||
PostStat.connection.should eq "secondary" | ||
end | ||
|
||
it "can load data from the default database" do | ||
temporary do | ||
reinit | ||
|
||
p = Post.new({title: "some post"}) | ||
p.save | ||
p.persisted?.should be_true | ||
end | ||
end | ||
|
||
it "can insert data into the secondary database" do | ||
temporary do | ||
reinit | ||
p = PostStat.new({post_id: 1}) | ||
p.save | ||
p.persisted?.should be_true | ||
p.post_id.should eq(1) | ||
end | ||
end | ||
|
||
it "can update data on the secondary database" do | ||
temporary do | ||
reinit | ||
p = PostStat.new({post_id: 1}) | ||
p.save | ||
|
||
p.post_id = 2 | ||
p.save | ||
|
||
p = PostStat.query.first.not_nil! | ||
p.post_id.should eq(2) | ||
end | ||
end | ||
end | ||
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
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