| 
1319 | 1319 |       end  | 
1320 | 1320 | 
 
  | 
1321 | 1321 |       let :options do  | 
1322 |  | -        AnnotateRb::Options.new({classified_sort: false, with_comment: true})  | 
 | 1322 | +        AnnotateRb::Options.new({classified_sort: false, with_comment: true, with_column_comments: true})  | 
1323 | 1323 |       end  | 
1324 | 1324 | 
 
  | 
1325 | 1325 |       let :columns do  | 
 | 
1358 | 1358 |       end  | 
1359 | 1359 | 
 
  | 
1360 | 1360 |       let :options do  | 
1361 |  | -        AnnotateRb::Options.new({classified_sort: false, with_comment: true})  | 
 | 1361 | +        AnnotateRb::Options.new({classified_sort: false, with_comment: true, with_column_comments: true})  | 
1362 | 1362 |       end  | 
1363 | 1363 | 
 
  | 
1364 | 1364 |       let :columns do  | 
 | 
1405 | 1405 |       end  | 
1406 | 1406 | 
 
  | 
1407 | 1407 |       let :options do  | 
1408 |  | -        AnnotateRb::Options.new({classified_sort: false, with_comment: true})  | 
 | 1408 | +        AnnotateRb::Options.new({classified_sort: false, with_comment: true, with_column_comments: true})  | 
1409 | 1409 |       end  | 
1410 | 1410 | 
 
  | 
1411 | 1411 |       let :columns do  | 
 | 
1851 | 1851 |       end  | 
1852 | 1852 | 
 
  | 
1853 | 1853 |       let :options do  | 
1854 |  | -        {format_rdoc: true, with_comment: true}  | 
 | 1854 | +        {format_rdoc: true, with_comment: true, with_column_comments: true}  | 
1855 | 1855 |       end  | 
1856 | 1856 | 
 
  | 
1857 | 1857 |       let :columns do  | 
 | 
1899 | 1899 |       end  | 
1900 | 1900 | 
 
  | 
1901 | 1901 |       let :options do  | 
1902 |  | -        {format_markdown: true, with_comment: true}  | 
 | 1902 | +        {format_markdown: true, with_comment: true, with_column_comments: true}  | 
1903 | 1903 |       end  | 
1904 | 1904 | 
 
  | 
1905 | 1905 |       let :columns do  | 
 | 
1968 | 1968 |       end  | 
1969 | 1969 |     end  | 
1970 | 1970 |   end  | 
 | 1971 | + | 
 | 1972 | +  describe "#schema_header_text" do  | 
 | 1973 | +    subject do  | 
 | 1974 | +      described_class.new(klass, options).schema_header_text  | 
 | 1975 | +    end  | 
 | 1976 | + | 
 | 1977 | +    let(:table_exists) { true }  | 
 | 1978 | +    let(:table_comment) { "" }  | 
 | 1979 | + | 
 | 1980 | +    let(:connection) do  | 
 | 1981 | +      indexes = []  | 
 | 1982 | +      foreign_keys = []  | 
 | 1983 | + | 
 | 1984 | +      mock_connection_with_table_fields(  | 
 | 1985 | +        indexes,  | 
 | 1986 | +        foreign_keys,  | 
 | 1987 | +        table_exists,  | 
 | 1988 | +        table_comment  | 
 | 1989 | +      )  | 
 | 1990 | +    end  | 
 | 1991 | + | 
 | 1992 | +    let :klass do  | 
 | 1993 | +      primary_key = nil  | 
 | 1994 | +      columns = []  | 
 | 1995 | + | 
 | 1996 | +      mock_class_with_custom_connection(  | 
 | 1997 | +        :users,  | 
 | 1998 | +        primary_key,  | 
 | 1999 | +        columns,  | 
 | 2000 | +        connection  | 
 | 2001 | +      )  | 
 | 2002 | +    end  | 
 | 2003 | + | 
 | 2004 | +    context "with no options set" do  | 
 | 2005 | +      let :options do  | 
 | 2006 | +        AnnotateRb::Options.new({})  | 
 | 2007 | +      end  | 
 | 2008 | + | 
 | 2009 | +      let(:expected_header) do  | 
 | 2010 | +        <<~HEADER  | 
 | 2011 | +          #  | 
 | 2012 | +          # Table name: users  | 
 | 2013 | +          #  | 
 | 2014 | +        HEADER  | 
 | 2015 | +      end  | 
 | 2016 | + | 
 | 2017 | +      it "returns the schema header" do  | 
 | 2018 | +        is_expected.to eq(expected_header)  | 
 | 2019 | +      end  | 
 | 2020 | +    end  | 
 | 2021 | + | 
 | 2022 | +    context "with `with_comment: true`" do  | 
 | 2023 | +      context "with `with_table_comments: true` and table has comments" do  | 
 | 2024 | +        let :options do  | 
 | 2025 | +          AnnotateRb::Options.new({with_comment: true, with_table_comments: true})  | 
 | 2026 | +        end  | 
 | 2027 | + | 
 | 2028 | +        let(:table_comment) { "table_comments" }  | 
 | 2029 | + | 
 | 2030 | +        let(:expected_header) do  | 
 | 2031 | +          <<~HEADER  | 
 | 2032 | +            #  | 
 | 2033 | +            # Table name: users(table_comments)  | 
 | 2034 | +            #  | 
 | 2035 | +          HEADER  | 
 | 2036 | +        end  | 
 | 2037 | + | 
 | 2038 | +        it "returns the header with the table comment" do  | 
 | 2039 | +          is_expected.to eq(expected_header)  | 
 | 2040 | +        end  | 
 | 2041 | +      end  | 
 | 2042 | + | 
 | 2043 | +      context "with `with_table_comments: true` and table does not have comments" do  | 
 | 2044 | +        let :options do  | 
 | 2045 | +          AnnotateRb::Options.new({with_comment: true, with_table_comments: true})  | 
 | 2046 | +        end  | 
 | 2047 | + | 
 | 2048 | +        let :klass do  | 
 | 2049 | +          primary_key = nil  | 
 | 2050 | +          columns = []  | 
 | 2051 | +          indexes = []  | 
 | 2052 | +          foreign_keys = []  | 
 | 2053 | + | 
 | 2054 | +          mock_class(  | 
 | 2055 | +            :users,  | 
 | 2056 | +            primary_key,  | 
 | 2057 | +            columns,  | 
 | 2058 | +            indexes,  | 
 | 2059 | +            foreign_keys  | 
 | 2060 | +          )  | 
 | 2061 | +        end  | 
 | 2062 | + | 
 | 2063 | +        let(:expected_header) do  | 
 | 2064 | +          <<~HEADER  | 
 | 2065 | +            #  | 
 | 2066 | +            # Table name: users  | 
 | 2067 | +            #  | 
 | 2068 | +          HEADER  | 
 | 2069 | +        end  | 
 | 2070 | + | 
 | 2071 | +        it "returns the header without table comments" do  | 
 | 2072 | +          is_expected.to eq(expected_header)  | 
 | 2073 | +        end  | 
 | 2074 | +      end  | 
 | 2075 | + | 
 | 2076 | +      context "with `with_table_comments: false` and table has comments" do  | 
 | 2077 | +        let :options do  | 
 | 2078 | +          AnnotateRb::Options.new({with_comment: true, with_table_comments: false})  | 
 | 2079 | +        end  | 
 | 2080 | + | 
 | 2081 | +        let(:table_comment) { "table_comments" }  | 
 | 2082 | + | 
 | 2083 | +        let(:expected_header) do  | 
 | 2084 | +          <<~HEADER  | 
 | 2085 | +            #  | 
 | 2086 | +            # Table name: users  | 
 | 2087 | +            #  | 
 | 2088 | +          HEADER  | 
 | 2089 | +        end  | 
 | 2090 | + | 
 | 2091 | +        it "returns the header without the table comment" do  | 
 | 2092 | +          is_expected.to eq(expected_header)  | 
 | 2093 | +        end  | 
 | 2094 | +      end  | 
 | 2095 | +    end  | 
 | 2096 | + | 
 | 2097 | +    context "with `with_comment: false`" do  | 
 | 2098 | +      context "with `with_table_comments: true` and table has comments" do  | 
 | 2099 | +        let :options do  | 
 | 2100 | +          AnnotateRb::Options.new({with_comment: false, with_table_comments: true})  | 
 | 2101 | +        end  | 
 | 2102 | + | 
 | 2103 | +        let(:table_comment) { "table_comments" }  | 
 | 2104 | + | 
 | 2105 | +        let(:expected_header) do  | 
 | 2106 | +          <<~HEADER  | 
 | 2107 | +            #  | 
 | 2108 | +            # Table name: users  | 
 | 2109 | +            #  | 
 | 2110 | +          HEADER  | 
 | 2111 | +        end  | 
 | 2112 | + | 
 | 2113 | +        it "returns the header without the table comment" do  | 
 | 2114 | +          is_expected.to eq(expected_header)  | 
 | 2115 | +        end  | 
 | 2116 | +      end  | 
 | 2117 | + | 
 | 2118 | +      context "with `with_table_comments: false` and table has comments" do  | 
 | 2119 | +        let :options do  | 
 | 2120 | +          AnnotateRb::Options.new({with_comment: false, with_table_comments: false})  | 
 | 2121 | +        end  | 
 | 2122 | + | 
 | 2123 | +        let(:table_comment) { "table_comments" }  | 
 | 2124 | + | 
 | 2125 | +        let(:expected_header) do  | 
 | 2126 | +          <<~HEADER  | 
 | 2127 | +            #  | 
 | 2128 | +            # Table name: users  | 
 | 2129 | +            #  | 
 | 2130 | +          HEADER  | 
 | 2131 | +        end  | 
 | 2132 | + | 
 | 2133 | +        it "returns the header without the table comment" do  | 
 | 2134 | +          is_expected.to eq(expected_header)  | 
 | 2135 | +        end  | 
 | 2136 | +      end  | 
 | 2137 | +    end  | 
 | 2138 | +  end  | 
1971 | 2139 | end  | 
0 commit comments