|
4 | 4 |
|
5 | 5 | RSpec.describe SupportTableData::Documentation::TypeInference do |
6 | 6 | describe ".value_type" do |
7 | | - it "returns the class of the value returned by the helper method" do |
| 7 | + it "returns the class of the value from the named instance data" do |
8 | 8 | # Group has named_instance_attribute_helpers :group_id, :name |
9 | | - expect(described_class.value_type(Group, "primary_name")).to eq(String) |
10 | | - expect(described_class.value_type(Group, "primary_group_id")).to eq(Integer) |
| 9 | + expect(described_class.value_type(Group, "primary", "name")).to eq(String) |
| 10 | + expect(described_class.value_type(Group, "primary", "group_id")).to eq(Integer) |
11 | 11 | end |
12 | 12 |
|
13 | | - it "returns nil when the method is not defined" do |
14 | | - expect(described_class.value_type(Group, "not_a_real_method")).to be_nil |
| 13 | + it "returns nil when the attribute is not present in the named instance data" do |
| 14 | + expect(described_class.value_type(Group, "primary", "not_a_real_attribute")).to be_nil |
15 | 15 | end |
16 | 16 |
|
17 | | - it "does not call the database for finder methods" do |
18 | | - # Sanity check: this confirms we are calling literal-returning helpers, |
19 | | - # not finder methods. Calling Group.primary would hit the DB; we should |
20 | | - # never invoke value_type on it. |
| 17 | + it "returns nil when the named instance does not exist" do |
| 18 | + expect(described_class.value_type(Group, "not_a_real_instance", "name")).to be_nil |
| 19 | + end |
| 20 | + |
| 21 | + it "does not invoke the generated helper methods" do |
| 22 | + # The generated method may be wrapped (e.g. deprecated) to raise, so we |
| 23 | + # must read the value from the data file rather than calling the method. |
21 | 24 | expect(Group).not_to receive(:primary) |
22 | | - described_class.value_type(Group, "primary_name") |
| 25 | + expect(Group).not_to receive(:primary_name) |
| 26 | + described_class.value_type(Group, "primary", "name") |
23 | 27 | end |
24 | 28 | end |
25 | 29 |
|
|
0 commit comments