Skip to content

Commit

Permalink
Unit test, yay!
Browse files Browse the repository at this point in the history
Review response to #293 (review)
  • Loading branch information
Hello there authored and yuzisee committed Feb 3, 2025
1 parent c1548ce commit 1fa11ce
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/rbs_rails/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,9 @@ def authenticate_#{attribute}: (String) -> (#{klass_name} | false)
end
end
class_name_opt = optional(class_name)
column_type = col.null ? class_name_opt : class_name
# If the DB says the column can be null, we need `<type>?`
# ...but if the type is already `untyped` there's no point in writing `untyped?`
column_type = (col.null && class_name != 'untyped') ? class_name_opt : class_name
sig = <<~EOS
def #{col.name}: () -> #{column_type}
def #{col.name}=: (#{column_type}) -> #{column_type}
Expand Down
4 changes: 4 additions & 0 deletions test/app/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ class User < ApplicationRecord
has_and_belongs_to_many :blogs
has_secure_password

serialize :phone_numbers, Array
serialize :contact_info, Hash
serialize :family_tree, JSON

has_one_attached :avatar

enum status: {
Expand Down
3 changes: 3 additions & 0 deletions test/app/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
create_table "users", force: :cascade do |t|
t.string "name", null: false
t.integer "age", null: false
t.string "phone_numbers"
t.string "contact_info"
t.string "family_tree"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
Expand Down
108 changes: 108 additions & 0 deletions test/expectations/user.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,114 @@ class User < ::ApplicationRecord

def clear_age_change: () -> void

def phone_numbers: () -> ::Array[untyped]

def phone_numbers=: (::Array[untyped]) -> ::Array[untyped]

def phone_numbers?: () -> bool

def phone_numbers_changed?: () -> bool

def phone_numbers_change: () -> [ ::Array[untyped]?, ::Array[untyped]? ]

def phone_numbers_will_change!: () -> void

def phone_numbers_was: () -> ::Array[untyped]?

def phone_numbers_previously_changed?: () -> bool

def phone_numbers_previous_change: () -> ::Array[::Array[untyped]?]?

def phone_numbers_previously_was: () -> ::Array[untyped]?

def phone_numbers_before_last_save: () -> ::Array[untyped]?

def phone_numbers_change_to_be_saved: () -> ::Array[::Array[untyped]?]?

def phone_numbers_in_database: () -> ::Array[untyped]?

def saved_change_to_phone_numbers: () -> ::Array[::Array[untyped]?]?

def saved_change_to_phone_numbers?: () -> bool

def will_save_change_to_phone_numbers?: () -> bool

def restore_phone_numbers!: () -> void

def clear_phone_numbers_change: () -> void

def contact_info: () -> ::Hash[untyped, untyped]

def contact_info=: (::Hash[untyped, untyped]) -> ::Hash[untyped, untyped]

def contact_info?: () -> bool

def contact_info_changed?: () -> bool

def contact_info_change: () -> [ ::Hash[untyped, untyped]?, ::Hash[untyped, untyped]? ]

def contact_info_will_change!: () -> void

def contact_info_was: () -> ::Hash[untyped, untyped]?

def contact_info_previously_changed?: () -> bool

def contact_info_previous_change: () -> ::Array[::Hash[untyped, untyped]?]?

def contact_info_previously_was: () -> ::Hash[untyped, untyped]?

def contact_info_before_last_save: () -> ::Hash[untyped, untyped]?

def contact_info_change_to_be_saved: () -> ::Array[::Hash[untyped, untyped]?]?

def contact_info_in_database: () -> ::Hash[untyped, untyped]?

def saved_change_to_contact_info: () -> ::Array[::Hash[untyped, untyped]?]?

def saved_change_to_contact_info?: () -> bool

def will_save_change_to_contact_info?: () -> bool

def restore_contact_info!: () -> void

def clear_contact_info_change: () -> void

def family_tree: () -> untyped

def family_tree=: (untyped) -> untyped

def family_tree?: () -> bool

def family_tree_changed?: () -> bool

def family_tree_change: () -> [ untyped, untyped ]

def family_tree_will_change!: () -> void

def family_tree_was: () -> untyped

def family_tree_previously_changed?: () -> bool

def family_tree_previous_change: () -> ::Array[untyped]?

def family_tree_previously_was: () -> untyped

def family_tree_before_last_save: () -> untyped

def family_tree_change_to_be_saved: () -> ::Array[untyped]?

def family_tree_in_database: () -> untyped

def saved_change_to_family_tree: () -> ::Array[untyped]?

def saved_change_to_family_tree?: () -> bool

def will_save_change_to_family_tree?: () -> bool

def restore_family_tree!: () -> void

def clear_family_tree_change: () -> void

def created_at: () -> ::ActiveSupport::TimeWithZone

def created_at=: (::ActiveSupport::TimeWithZone) -> ::ActiveSupport::TimeWithZone
Expand Down

0 comments on commit 1fa11ce

Please sign in to comment.