-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaasm_rbs_spec.rb
130 lines (112 loc) · 4.08 KB
/
aasm_rbs_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# frozen_string_literal: true
require 'spec_helper'
require_relative '../lib/aasm_rbs'
require_relative 'classes/job'
require_relative 'classes/user'
require_relative 'classes/refund'
RSpec.describe AasmRbs do
describe '.run' do
context 'with a non ActiveRecord model' do
let(:klass_name) { 'Job' }
let(:expected_rbs) do
<<~RBS
class Job
STATE_SLEEPING: String
STATE_RUNNING: String
STATE_CLEANING: String
def sleeping?: () -> bool
def running?: () -> bool
def cleaning?: () -> bool
def run: (*untyped) -> bool
def run!: (*untyped) -> bool
def run_without_validation!: (*untyped) -> bool
def may_run?: (*untyped) -> bool
def clean: (*untyped) -> bool
def clean!: (*untyped) -> bool
def clean_without_validation!: (*untyped) -> bool
def may_clean?: (*untyped) -> bool
def sleep: (*untyped) -> bool
def sleep!: (*untyped) -> bool
def sleep_without_validation!: (*untyped) -> bool
def may_sleep?: (*untyped) -> bool
end
RBS
end
it 'returns the right RBS' do
actual_output = described_class.run(klass_name)
expect(actual_output).to eq(expected_rbs)
end
end
context 'with an ActiveRecord model that disables AASM automatic scopes' do
let(:klass_name) { 'Refund' }
let(:expected_rbs) do
<<~RBS
class Refund < ApplicationRecord
STATE_PENDING: String
STATE_PROCESSED: String
STATE_FAILED: String
def pending?: () -> bool
def processed?: () -> bool
def failed?: () -> bool
def process: (*untyped) -> bool
def process!: (*untyped) -> bool
def process_without_validation!: (*untyped) -> bool
def may_process?: (*untyped) -> bool
def fail: (*untyped) -> bool
def fail!: (*untyped) -> bool
def fail_without_validation!: (*untyped) -> bool
def may_fail?: (*untyped) -> bool
end
RBS
end
it 'returns the right RBS' do
actual_output = described_class.run(klass_name)
expect(actual_output).to eq(expected_rbs)
end
end
context 'with an ActiveRecord model that enables AASM automatic scopes' do
let(:klass_name) { 'User' }
let(:expected_rbs) do
<<~RBS
class User < ApplicationRecord
STATE_PENDING: String
STATE_APPROVED: String
STATE_REJECTED: String
def self.pending: () -> ActiveRecord_Relation
def self.approved: () -> ActiveRecord_Relation
def self.rejected: () -> ActiveRecord_Relation
def pending?: () -> bool
def approved?: () -> bool
def rejected?: () -> bool
def approve: (*untyped) -> bool
def approve!: (*untyped) -> bool
def approve_without_validation!: (*untyped) -> bool
def may_approve?: (*untyped) -> bool
def reject: (*untyped) -> bool
def reject!: (*untyped) -> bool
def reject_without_validation!: (*untyped) -> bool
def may_reject?: (*untyped) -> bool
class ActiveRecord_Relation < ::ActiveRecord::Relation
include GeneratedRelationMethods
include _ActiveRecord_Relation[User, Integer]
include Enumerable[User]
end
end
RBS
end
it 'returns the right RBS' do
actual_output = described_class.run(klass_name)
expect(actual_output).to eq(expected_rbs)
end
end
context "with an invalid class name" do
let(:klass) { "SomeClass" }
it "correctly aborts", :aggregate_failures do
expect { described_class.run(klass) }.to raise_error(SystemExit) do |error|
expect(error.status).to eq(1)
expect(error.message).to eq('aasm_rbs received an invalid class name.')
end
end
end
end
end