-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #348 from RailsEventStore/0-28
Do not double serialize YAML in Legacy Repository
- Loading branch information
Showing
6 changed files
with
192 additions
and
2 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
84 changes: 84 additions & 0 deletions
84
rails_event_store_active_record-legacy/spec/legacy_schema_compatibility_spec.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,84 @@ | ||
require 'spec_helper' | ||
require 'pathname' | ||
require 'childprocess' | ||
require 'active_record' | ||
require 'logger' | ||
require 'ruby_event_store' | ||
|
||
|
||
class EventAll < RubyEventStore::Event | ||
end | ||
class EventA1 < RubyEventStore::Event | ||
end | ||
class EventA2 < RubyEventStore::Event | ||
end | ||
class EventB1 < RubyEventStore::Event | ||
end | ||
class EventB2 < RubyEventStore::Event | ||
end | ||
|
||
RSpec.describe "legacy schema compatibility" do | ||
include SchemaHelper | ||
|
||
def silence_stderr | ||
$stderr = StringIO.new | ||
yield | ||
$stderr = STDERR | ||
end | ||
|
||
around(:each) do |example| | ||
begin | ||
ActiveRecord::Schema.verbose = $verbose | ||
fill_data_using_older_gem | ||
establish_database_connection | ||
silence_stderr { example.run } | ||
ensure | ||
drop_legacy_database | ||
end | ||
end | ||
|
||
specify "reading events" do | ||
skip("in-memory sqlite cannot run this test") if ENV['DATABASE_URL'].include?(":memory:") | ||
|
||
event = client.read_all_streams_forward[0] | ||
expect(event.metadata[:timestamp]).to be_kind_of(Time) | ||
end | ||
|
||
specify "writing events" do | ||
skip("in-memory sqlite cannot run this test") if ENV['DATABASE_URL'].include?(":memory:") | ||
client.append_to_stream( | ||
write_event = EventAll.new(metadata: { foo: 13 }), | ||
stream_name: 'foo', | ||
expected_version: -1 | ||
) | ||
|
||
read_event = client.read_stream_events_forward('foo')[0] | ||
expect(read_event).to eq(write_event) | ||
expect(read_event.metadata[:foo]).to eq(13) | ||
expect(read_event.metadata[:timestamp]).to be_kind_of(Time) | ||
end | ||
|
||
private | ||
|
||
let(:client) { RubyEventStore::Client.new(repository: RailsEventStoreActiveRecord::Legacy::EventRepository.new) } | ||
|
||
def fill_data_using_older_gem | ||
pathname = Pathname.new(__FILE__).dirname | ||
cwd = pathname.join("schema") | ||
FileUtils.rm(cwd.join("Gemfile.lock")) if File.exists?(cwd.join("Gemfile.lock")) | ||
process = ChildProcess.build("bundle", "exec", "ruby", "fill_data.rb") | ||
process.environment['BUNDLE_GEMFILE'] = cwd.join('Gemfile') | ||
process.environment['DATABASE_URL'] = ENV['DATABASE_URL'] | ||
process.environment['RAILS_VERSION'] = ENV['RAILS_VERSION'] | ||
process.cwd = cwd | ||
process.io.stdout = $stdout | ||
process.io.stderr = $stderr | ||
process.start | ||
begin | ||
process.poll_for_exit(10) | ||
rescue ChildProcess::TimeoutError | ||
process.stop | ||
end | ||
expect(process.exit_code).to eq(0) | ||
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
source 'https://rubygems.org' | ||
gem 'rails_event_store', '0.18.2' | ||
gem 'rails', ENV['RAILS_VERSION'] | ||
gem 'sqlite3', '1.3.13' | ||
gem 'pg', '0.21' | ||
gem 'mysql2', '0.4.10' |
97 changes: 97 additions & 0 deletions
97
rails_event_store_active_record-legacy/spec/schema/fill_data.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,97 @@ | ||
require 'rails/generators' # doh | ||
require 'rails_event_store_active_record' | ||
require 'ruby_event_store' | ||
require 'logger' | ||
|
||
$verbose = ENV.has_key?('VERBOSE') ? true : false | ||
|
||
ActiveRecord::Base.logger = Logger.new(STDOUT) if $verbose | ||
ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'].gsub("db.sqlite3", "../../db.sqlite3")) | ||
ActiveRecord::Schema.define do | ||
self.verbose = $verbose | ||
create_table(:event_store_events, force: false) do |t| | ||
t.string :stream, null: false | ||
t.string :event_type, null: false | ||
t.string :event_id, null: false | ||
t.text :metadata | ||
t.text :data, null: false | ||
t.datetime :created_at, null: false | ||
end | ||
add_index :event_store_events, :stream | ||
add_index :event_store_events, :created_at | ||
add_index :event_store_events, :event_type | ||
add_index :event_store_events, :event_id, unique: true | ||
end | ||
|
||
class EventAll < RubyEventStore::Event | ||
end | ||
class EventA1 < RubyEventStore::Event | ||
end | ||
class EventA2 < RubyEventStore::Event | ||
end | ||
class EventB1 < RubyEventStore::Event | ||
end | ||
class EventB2 < RubyEventStore::Event | ||
end | ||
|
||
client = RubyEventStore::Client.new( | ||
repository: RailsEventStoreActiveRecord::EventRepository.new | ||
) | ||
client.append_to_stream(EventAll.new(data: { | ||
all: true, | ||
a: 1, | ||
text: "text", | ||
}, event_id: "94b297a3-5a29-4942-9038-3efeceb4d905")) | ||
client.append_to_stream(EventAll.new(data: { | ||
all: true, | ||
a: 2, | ||
date: Date.new(2017, 10, 11), | ||
}, event_id: "6a31b594-7d8f-428b-916f-496f6da05bfd")) | ||
client.append_to_stream(EventAll.new(data: { | ||
all: true, | ||
a: 3, | ||
time: Time.new(2017,10, 10, 12), | ||
}, event_id: "011cc5c4-d638-4785-9aa0-7d6a2d3e2a58")) | ||
|
||
|
||
|
||
client.append_to_stream(EventA1.new(data: { | ||
a1: true, | ||
decimal: BigDecimal.new("20.00"), | ||
}, event_id: "d39cb65f-bc3c-4fbb-9470-52bf5e322bba"), | ||
stream_name: "Order-1", | ||
) | ||
client.append_to_stream(EventA2.new(data: { | ||
all: true, | ||
symbol: :symbol, | ||
}, event_id: "f2cecc51-adb1-4d83-b3ca-483d26311f03"), | ||
stream_name: "Order-1", | ||
) | ||
client.append_to_stream(EventA1.new(data: { | ||
all: true, | ||
symbol: :symbol, | ||
}, event_id: "600e1e1b-7fdf-44e2-a406-8b612c67c881"), | ||
stream_name: "Order-1", | ||
) | ||
|
||
|
||
client.append_to_stream(EventB1.new(data: { | ||
a1: true, | ||
decimal: BigDecimal.new("20.00"), | ||
}, event_id: "9009df88-6044-4a62-b7ae-098c42a9c5e1"), | ||
stream_name: "WroclawBuyers", | ||
) | ||
client.append_to_stream(EventB2.new(data: { | ||
all: true, | ||
symbol: :symbol, | ||
}, event_id: "cefdd213-0c92-46f6-bbdf-3ea9542d969a"), | ||
stream_name: "WroclawBuyers", | ||
) | ||
client.append_to_stream(EventB2.new(data: { | ||
all: true, | ||
symbol: :symbol, | ||
}, event_id: "36775fcd-c5d8-49c9-bf70-f460ba12d7c2"), | ||
stream_name: "WroclawBuyers", | ||
) | ||
|
||
puts "filled" if $verbose |