Skip to content

Commit

Permalink
Enforce 1024 character limit on description value
Browse files Browse the repository at this point in the history
  • Loading branch information
dgoerlich committed Apr 11, 2016
1 parent 6bb98f3 commit 281d0e0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ data = { start_time: DateTime.now + 4.hours }
mail(to: to_email, subject: "Test", body: "test", sparkpost_data: data)
```

You can set a description for a transmission via the "sparkpost_data" as well:
You can set a description for a transmission via the "sparkpost_data" as well. The maximum length of the decription is 1024 characters - values
longer than the maxium will be truncated.

```
data = { description: "My Important Message" }
Expand Down
2 changes: 1 addition & 1 deletion lib/sparkpost_rails/delivery_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def prepare_skip_suppression_from sparkpost_data

def prepare_description_from sparkpost_data
if sparkpost_data[:description]
@data[:description] = sparkpost_data[:description]
@data[:description] = sparkpost_data[:description].truncate(1024)
end
end

Expand Down
11 changes: 11 additions & 0 deletions spec/description_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
expect(@delivery_method.data[:description]).to eq("Test Email")
end

it "truncates values longer than 1024 characters" do
raw_description = "X" * 1050
truncated_description = ("X" * 1021) + "..."

test_email = Mailer.test_email sparkpost_data: {description: raw_description}

@delivery_method.deliver!(test_email)

expect(@delivery_method.data[:description]).to eq(truncated_description)
end

it "does not include description element if not supplied" do
test_email = Mailer.test_email
@delivery_method.deliver!(test_email)
Expand Down

0 comments on commit 281d0e0

Please sign in to comment.