Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions test/models/mailbox_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
require "test_helper"

class MailboxTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
def setup
@mailbox = Mailbox.new
end

test "should be valid" do
assert @mailbox.valid?
end

test "should inherit from ApplicationRecord" do
assert_kind_of ApplicationRecord, @mailbox
end
end
58 changes: 55 additions & 3 deletions test/models/message_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,59 @@
require "test_helper"

class MessageTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
def setup
@message_thread = message_threads(:one)
@message = Message.new(
content: "Test message content",
message_thread: @message_thread
)
end

test "should be valid with content and message_thread" do
assert @message.valid?
end

test "should validate presence of content" do
@message.content = nil
assert_not @message.valid?
assert_includes @message.errors[:content], "can't be blank"
end

test "should belong to message_thread" do
assert_respond_to @message, :message_thread
assert_equal @message_thread, @message.message_thread
end

test "should have rich text content" do
assert_respond_to @message, :content
assert_respond_to @message, :rich_text_content
end

test "should have attachments" do
assert_respond_to @message, :attachments
end

test "should generate email_message_id before save" do
@message.save!
assert_not_nil @message.email_message_id
assert_match /.+@.+/, @message.email_message_id
end

test "should update message_thread current_email_message_id after create" do
original_message_id = @message_thread.current_email_message_id
@message.save!
@message_thread.reload
assert_equal @message.email_message_id, @message_thread.current_email_message_id
assert_not_equal original_message_id, @message_thread.current_email_message_id
end

test "should default order by created_at DESC" do
@message.save!
older_message = Message.create!(content: "Older message", message_thread: @message_thread)
newer_message = Message.create!(content: "Newer message", message_thread: @message_thread)

messages = Message.all
assert_equal newer_message, messages.first
assert_equal older_message, messages.second
end
end
47 changes: 44 additions & 3 deletions test/models/message_thread_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,48 @@
require "test_helper"

class MessageThreadTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
def setup
@message_thread = MessageThread.new(
recipients: ["test@example.com"],
subject: "Test Subject"
)
end

test "should be valid with recipients" do
assert @message_thread.valid?
end

test "should validate presence of recipients" do
@message_thread.recipients = nil
assert_not @message_thread.valid?
assert_includes @message_thread.errors[:recipients], "can't be blank"
end

test "should validate recipients length minimum" do
@message_thread.recipients = []
assert_not @message_thread.valid?
assert_includes @message_thread.errors[:recipients], "is too short (minimum is 1 character)"
end

test "should have many messages" do
assert_respond_to @message_thread, :messages
assert_respond_to @message_thread, :messages=
end

test "should accept nested attributes for messages" do
assert_respond_to @message_thread, :messages_attributes=
end

test "should include comfy cms with categories" do
assert_includes MessageThread.included_modules, Comfy::Cms::WithCategories
end

test "should have search scope" do
assert_respond_to MessageThread, :search_messages_content_body_or_subject_or_messages_from_or_recipients_contains
end

test "should have ransackable scopes" do
ransackable_scopes = MessageThread.ransackable_scopes
assert_includes ransackable_scopes, :search_messages_content_body_or_subject_or_messages_from_or_recipients_contains
end
end
63 changes: 60 additions & 3 deletions test/models/non_primitive_property_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,64 @@
require "test_helper"

class NonPrimitivePropertyTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
def setup
@api_namespace = api_namespaces(:one)
@non_primitive_property = NonPrimitiveProperty.new(
label: "Test Property",
field_type: :richtext,
content: "Test content",
api_namespace: @api_namespace
)
end

test "should be valid with all attributes" do
assert @non_primitive_property.valid?
end

test "should validate presence of label" do
@non_primitive_property.label = nil
assert_not @non_primitive_property.valid?
assert_includes @non_primitive_property.errors[:label], "can't be blank"
end

test "should belong to api_resource optionally" do
assert_respond_to @non_primitive_property, :api_resource
assert_respond_to @non_primitive_property, :api_resource=
end

test "should belong to api_namespace optionally" do
assert_respond_to @non_primitive_property, :api_namespace
assert_equal @api_namespace, @non_primitive_property.api_namespace
end

test "should have field_type enum" do
assert_respond_to @non_primitive_property, :field_type
assert_equal 0, NonPrimitiveProperty.field_types[:file]
assert_equal 1, NonPrimitiveProperty.field_types[:richtext]
end

test "should have rich text content" do
assert_respond_to @non_primitive_property, :content
assert_respond_to @non_primitive_property, :rich_text_content
end

test "should have attachment" do
assert_respond_to @non_primitive_property, :attachment
end

test "should respond to file_url method" do
assert_respond_to @non_primitive_property, :file_url
end

test "should identify file type correctly" do
@non_primitive_property.field_type = :file
assert @non_primitive_property.file?
assert_not @non_primitive_property.richtext?
end

test "should identify richtext type correctly" do
@non_primitive_property.field_type = :richtext
assert @non_primitive_property.richtext?
assert_not @non_primitive_property.file?
end
end
48 changes: 45 additions & 3 deletions test/models/sales_asset_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,49 @@
require "test_helper"

class SalesAssetTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
def setup
@sales_asset = SalesAsset.new(
name: "Test Sales Asset",
width: 800,
height: 600,
html: "<div><h1>Test Content</h1></div>"
)
end

test "should be valid with all attributes" do
assert @sales_asset.valid?
end

test "should validate presence of name" do
@sales_asset.name = nil
assert_not @sales_asset.valid?
assert_includes @sales_asset.errors[:name], "can't be blank"
end

test "should validate presence of width" do
@sales_asset.width = nil
assert_not @sales_asset.valid?
assert_includes @sales_asset.errors[:width], "can't be blank"
end

test "should validate presence of height" do
@sales_asset.height = nil
assert_not @sales_asset.valid?
assert_includes @sales_asset.errors[:height], "can't be blank"
end

test "should validate presence of html" do
@sales_asset.html = nil
assert_not @sales_asset.valid?
assert_includes @sales_asset.errors[:html], "can't be blank"
end

test "should generate friendly slug from name" do
@sales_asset.save!
assert_equal "test-sales-asset", @sales_asset.slug
end

test "should have render method" do
assert_respond_to @sales_asset, :render
end
end