FEATURE: phase 1 of supporting multiple email addresses

This commit is contained in:
Leo McArdle
2017-04-26 19:47:36 +01:00
committed by Guo Xiang Tan
parent 739794f0cb
commit d0b027d88d
35 changed files with 337 additions and 80 deletions

View File

@ -1,7 +1,7 @@
require 'rails_helper'
require 'column_dropper'
describe ColumnDropper do
RSpec.describe ColumnDropper do
def has_column?(table, column)
Topic.exec_sql("SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS
@ -48,5 +48,78 @@ describe ColumnDropper do
expect(dropped_proc_called).to eq(true)
end
end
describe '.mark_readonly' do
let(:table_name) { "table_with_readonly_column" }
before do
ActiveRecord::Base.exec_sql <<~SQL
CREATE TABLE #{table_name} (topic_id INTEGER, email TEXT);
INSERT INTO #{table_name} (topic_id, email)
VALUES (1, 'something@email.com');
SQL
described_class.mark_readonly(table_name, 'email')
end
after do
ActiveRecord::Base.exec_sql <<~SQL
DROP TABLE IF EXISTS #{table_name};
DROP TRIGGER IF EXISTS #{table_name}_email_readonly ON #{table_name};
SQL
end
it 'should prevent updates to the readonly column' do
expect do
ActiveRecord::Base.exec_sql <<~SQL
UPDATE #{table_name}
SET email = 'testing@email.com'
WHERE topic_id = 1;
SQL
end.to raise_error(
PG::RaiseException,
/Discourse: email in #{table_name} is readonly/
)
ActiveRecord::Base.exec_sql("ROLLBACK")
end
it 'should allow updates to the other columns' do
ActiveRecord::Base.exec_sql <<~SQL
UPDATE #{table_name}
SET topic_id = 2
WHERE topic_id = 1
SQL
expect(
ActiveRecord::Base.exec_sql("SELECT * FROM #{table_name};").values
).to include(["2", "something@email.com"])
end
it 'should prevent insertions to the readonly column' do
expect do
ActiveRecord::Base.exec_sql <<~SQL
INSERT INTO #{table_name} (topic_id, email)
VALUES (2, 'something@email.com');
SQL
end.to raise_error(
PG::RaiseException,
/Discourse: email in table_with_readonly_column is readonly/
)
ActiveRecord::Base.exec_sql("ROLLBACK")
end
it 'should allow insertions to the other columns' do
ActiveRecord::Base.exec_sql <<~SQL
INSERT INTO #{table_name} (topic_id)
VALUES (2);
SQL
expect(
ActiveRecord::Base.exec_sql("SELECT * FROM #{table_name} WHERE topic_id = 2;").values
).to include(["2", nil])
end
end
end

View File

@ -381,7 +381,7 @@ describe Email::Receiver do
it "invites everyone in the chain but emails configured as 'incoming' (via reply, group or category)" do
expect { process(:cc) }.to change(Topic, :count)
emails = Topic.last.allowed_users.pluck(:email)
emails = Topic.last.allowed_users.joins(:user_emails).pluck(:"user_emails.email")
expect(emails.size).to eq(3)
expect(emails).to include("someone@else.com", "discourse@bar.com", "wat@bar.com")
end