|
171 | 171 | expect(candidates).to eq([]) |
172 | 172 | end |
173 | 173 | end |
| 174 | + |
| 175 | + context "when given an include_blank option is true" do |
| 176 | + it "returns include_blank and placeholder options with '---'" do |
| 177 | + customer = create(:customer, territory: nil) |
| 178 | + association = Administrate::Field::BelongsTo.with_options( |
| 179 | + include_blank: true |
| 180 | + ) |
| 181 | + field = association.new( |
| 182 | + :territory, |
| 183 | + [], |
| 184 | + :edit, |
| 185 | + resource: customer |
| 186 | + ) |
| 187 | + |
| 188 | + tag_options = field.tag_options |
| 189 | + html_options = field.html_options |
| 190 | + |
| 191 | + expect(tag_options[:include_blank]).to eq("---") |
| 192 | + expect(html_options[:placeholder]).to eq("---") |
| 193 | + expect(html_options.dig(:data, :"selectize-required")).to be_nil |
| 194 | + end |
| 195 | + end |
| 196 | + |
| 197 | + context "when given an include_blank option is a string" do |
| 198 | + it "returns include_blank and placeholder options with the given string" do |
| 199 | + customer = create(:customer, territory: nil) |
| 200 | + association = Administrate::Field::BelongsTo.with_options( |
| 201 | + include_blank: "Select an option" |
| 202 | + ) |
| 203 | + field = association.new( |
| 204 | + :territory, |
| 205 | + [], |
| 206 | + :edit, |
| 207 | + resource: customer |
| 208 | + ) |
| 209 | + |
| 210 | + tag_options = field.tag_options |
| 211 | + html_options = field.html_options |
| 212 | + |
| 213 | + expect(tag_options[:include_blank]).to eq("Select an option") |
| 214 | + expect(html_options[:placeholder]).to eq("Select an option") |
| 215 | + expect(html_options.dig(:data, :"selectize-required")).to be_nil |
| 216 | + end |
| 217 | + end |
| 218 | + |
| 219 | + context "when given an include_blank option is false" do |
| 220 | + it "returns include_blank and placeholder options with nil" do |
| 221 | + customer = create(:customer, territory: nil) |
| 222 | + association = Administrate::Field::BelongsTo.with_options( |
| 223 | + include_blank: false |
| 224 | + ) |
| 225 | + field = association.new( |
| 226 | + :territory, |
| 227 | + [], |
| 228 | + :edit, |
| 229 | + resource: customer |
| 230 | + ) |
| 231 | + |
| 232 | + tag_options = field.tag_options |
| 233 | + html_options = field.html_options |
| 234 | + |
| 235 | + expect(tag_options[:include_blank]).to eq(nil) |
| 236 | + expect(html_options[:placeholder]).to eq(nil) |
| 237 | + expect(html_options.dig(:data, :"selectize-required")).to eq(true) |
| 238 | + end |
| 239 | + end |
174 | 240 | end |
175 | 241 |
|
176 | 242 | describe "primary_key option" do |
|
0 commit comments