spec/griddler/sendgrid/adapter_spec.rb in griddler-sendgrid-1.0.1 vs spec/griddler/sendgrid/adapter_spec.rb in griddler-sendgrid-1.1.0

- old
+ new

@@ -12,10 +12,11 @@ { text: 'hi', to: 'Hello World <hi@example.com>', cc: 'emily@example.com', from: 'There <there@example.com>', + charsets: { to: 'UTF-8', text: 'iso-8859-1' }.to_json } it 'changes attachments to an array of files' do params = default_params.merge( attachments: '2', @@ -127,15 +128,47 @@ normalized_params = normalize_params(params) normalized_params[:bcc].should eq [] end + it 'returns the charsets as a hash' do + normalized_params = normalize_params(default_params) + charsets = normalized_params[:charsets] + + charsets.should be_present + charsets[:text].should eq 'iso-8859-1' + charsets[:to].should eq 'UTF-8' + end + + it 'does not explode if charsets is not JSON-able' do + params = default_params.merge(charsets: 'This is not JSON') + + normalize_params(params)[:charsets].should eq({}) + end + + it 'defaults charsets to an empty hash if it is not specified in params' do + params = default_params.except(:charsets) + normalize_params(params)[:charsets].should eq({}) + end + + it 'normalizes the spam report into a griddler friendly format' do + normalized_params = normalize_params(default_params) + + normalized_params[:spam_report].should eq({ + score: '1.234', + report: 'Some spam report', + }) + end + def default_params { text: 'hi', to: '"Mr Fugushima at Fugu, Inc" <hi@example.com>, Foo bar <foo@example.com>, Eichhörnchen <squirrel@example.com>, <no-name@example.com>', cc: 'cc@example.com', from: 'there@example.com', envelope: "{\"to\":[\"johny@example.com\"], \"from\": [\"there@example.com\"]}", + charsets: { to: 'UTF-8', text: 'iso-8859-1' }.to_json, + spam_score: '1.234', + spam_report: 'Some spam report' } end end