spec/web_ui_spec.rb in katapult-0.3.0 vs spec/web_ui_spec.rb in katapult-0.4.0

- old
+ new

@@ -1,7 +1,7 @@ -require 'katapult/web_ui' -require 'katapult/model' +require 'katapult/elements/web_ui' +require 'katapult/elements/model' require 'katapult/application_model' describe Katapult::WebUI do subject { described_class.new 'web_ui' } @@ -35,46 +35,24 @@ end end describe '#model' do it 'returns the model object' do - subject = described_class.new('Customer', model: 'User') - model = Katapult::Model.new('User') + application_model.model 'User' - application_model.add_web_ui(subject) - application_model.add_model(model) + subject = described_class.new('Customer', + model: 'User', + application_model: application_model, + ) - expect(subject.model).to eql(model) + expect(subject.model).to be application_model.models.first end it 'detects the model from its own name, if not stated explicitly' do - subject = described_class.new('Customer') - model = Katapult::Model.new('Customer') + application_model.model 'Customer' + subject = described_class.new('Customer', application_model: application_model) - application_model.add_web_ui(subject) - application_model.add_model(model) - - expect(subject.model).to eql(model) - end - - it 'raises an error if it cannot find the model' do - subject = described_class.new('MissingModel') - application_model.add_web_ui(subject) - - expect{ subject.model }.to raise_error(Katapult::WebUI::UnknownModelError) - end - end - - describe '#render' do - it 'raises an error when its model does not have a label attribute' do - subject = described_class.new('user') - model = Katapult::Model.new('user') - - application_model.add_web_ui(subject) - application_model.add_model(model) - - expect{ subject.render }.to raise_error Katapult::WebUI::MissingLabelAttrError, - 'Cannot render a WebUI without a model with a label attribute' + expect(subject.model).to be application_model.models.first end end end