aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/test/models
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2018-06-01 14:24:06 -0400
committerGitHub <noreply@github.com>2018-06-01 14:24:06 -0400
commitc1844477a1461ffc9db3d899212f608c2a0c77c9 (patch)
tree204ef39c0a71ba5a96a79e6b18addd711aba1c0b /activestorage/test/models
parentc61d67296c2e8a0682779c2f4eb9acea0c4b4a7e (diff)
parent6c7e6abfaad149da02dbec4e4f2bd62c5d68805f (diff)
downloadrails-c1844477a1461ffc9db3d899212f608c2a0c77c9.tar.gz
rails-c1844477a1461ffc9db3d899212f608c2a0c77c9.tar.bz2
rails-c1844477a1461ffc9db3d899212f608c2a0c77c9.zip
Merge pull request #33018 from kddeisz/defined-attachments
ActiveStorage reflection
Diffstat (limited to 'activestorage/test/models')
-rw-r--r--activestorage/test/models/reflection_test.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/activestorage/test/models/reflection_test.rb b/activestorage/test/models/reflection_test.rb
new file mode 100644
index 0000000000..da866ca996
--- /dev/null
+++ b/activestorage/test/models/reflection_test.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+require "test_helper"
+
+class ActiveStorage::ReflectionTest < ActiveSupport::TestCase
+ test "allows reflecting for all attachment" do
+ expected_classes =
+ User.reflect_on_all_attachments.all? do |reflection|
+ reflection.is_a?(ActiveStorage::Reflection::HasOneAttachedReflection) ||
+ reflection.is_a?(ActiveStorage::Reflection::HasManyAttachedReflection)
+ end
+
+ assert expected_classes
+ end
+
+ test "allows reflecting on a singular has_one_attached attachment" do
+ reflection = User.reflect_on_attachment(:avatar)
+
+ assert_equal :avatar, reflection.name
+ assert_equal :has_one_attached, reflection.macro
+ end
+
+ test "allows reflecting on a singular has_many_attached attachment" do
+ reflection = User.reflect_on_attachment(:highlights)
+
+ assert_equal :highlights, reflection.name
+ assert_equal :has_many_attached, reflection.macro
+ end
+end