spec/integration/action/slice_configuration_spec.rb in hanami-2.0.0.rc1 vs spec/integration/action/slice_configuration_spec.rb in hanami-2.0.0

- old
+ new

@@ -32,28 +32,29 @@ describe "inheriting from app-level base class" do describe "app-level base class" do it "applies default actions config from the app", :aggregate_failures do prepare_app - expect(TestApp::Action.config.default_request_format).to eq :html - expect(TestApp::Action.config.default_response_format).to eq :html + expect(TestApp::Action.config.formats.values).to eq [] end it "applies actions config from the app" do - Hanami.app.config.actions.default_response_format = :json + Hanami.app.config.actions.format :json prepare_app - expect(TestApp::Action.config.default_response_format).to eq :json + expect(TestApp::Action.config.formats.values).to eq [:json] end it "does not override config in the base class" do - Hanami.app.config.actions.default_response_format = :csv + Hanami.app.config.actions.format :csv prepare_app - TestApp::Action.config.default_response_format = :json + TestApp::Action.config.format :json + + expect(TestApp::Action.config.formats.values).to eq [:json] end end describe "subclass in app" do before do @@ -72,28 +73,27 @@ end it "applies default actions config from the app", :aggregate_failures do prepare_app - expect(TestApp::Actions::Articles::Index.config.default_request_format).to eq :html - expect(TestApp::Actions::Articles::Index.config.default_response_format).to eq :html + expect(TestApp::Actions::Articles::Index.config.formats.values).to eq [] end it "applies actions config from the app" do - Hanami.app.config.actions.default_response_format = :json + Hanami.app.config.actions.format :json prepare_app - expect(TestApp::Actions::Articles::Index.config.default_response_format).to eq :json + expect(TestApp::Actions::Articles::Index.config.formats.values).to eq [:json] end it "applies config from the base class" do prepare_app - TestApp::Action.config.default_response_format = :json + TestApp::Action.config.format :json - expect(TestApp::Actions::Articles::Index.config.default_response_format).to eq :json + expect(TestApp::Actions::Articles::Index.config.formats.values).to eq [:json] end end describe "subclass in slice" do before do @@ -112,28 +112,27 @@ end it "applies default actions config from the app", :aggregate_failures do prepare_app - expect(Admin::Actions::Articles::Index.config.default_request_format).to eq :html - expect(Admin::Actions::Articles::Index.config.default_response_format).to eq :html + expect(Admin::Actions::Articles::Index.config.formats.values).to eq [] end it "applies actions config from the app" do - Hanami.app.config.actions.default_response_format = :json + Hanami.app.config.actions.format :json prepare_app - expect(Admin::Actions::Articles::Index.config.default_response_format).to eq :json + expect(Admin::Actions::Articles::Index.config.formats.values).to eq [:json] end it "applies config from the base class" do prepare_app - TestApp::Action.config.default_response_format = :json + TestApp::Action.config.format :json - expect(Admin::Actions::Articles::Index.config.default_response_format).to eq :json + expect(Admin::Actions::Articles::Index.config.formats.values).to eq [:json] end end end describe "inheriting from a slice-level base class, in turn inheriting from an app-level base class" do @@ -150,64 +149,63 @@ describe "slice-level base class" do it "applies default actions config from the app", :aggregate_failures do prepare_app - expect(Admin::Action.config.default_request_format).to eq :html - expect(Admin::Action.config.default_response_format).to eq :html + expect(Admin::Action.config.formats.values).to eq [] end it "applies actions config from the app" do - Hanami.app.config.actions.default_response_format = :json + Hanami.app.config.actions.format :json prepare_app - expect(Admin::Action.config.default_response_format).to eq :json + expect(Admin::Action.config.formats.values).to eq [:json] end it "applies config from the app base class" do prepare_app - TestApp::Action.config.default_response_format = :json + TestApp::Action.config.format :json - expect(Admin::Action.config.default_response_format).to eq :json + expect(Admin::Action.config.formats.values).to eq [:json] end context "slice actions config present" do before do with_directory(@dir) do write "config/slices/admin.rb", <<~'RUBY' module Admin class Slice < Hanami::Slice - config.actions.default_response_format = :csv + config.actions.format :csv end end RUBY end end it "applies actions config from the slice" do prepare_app - expect(Admin::Action.config.default_response_format).to eq :csv + expect(Admin::Action.config.formats.values).to eq [:csv] end it "prefers actions config from the slice over config from the app-level base class" do prepare_app - TestApp::Action.config.default_response_format = :json + TestApp::Action.config.format :json - expect(Admin::Action.config.default_response_format).to eq :csv + expect(Admin::Action.config.formats.values).to eq [:csv] end it "prefers config from the base class over actions config from the slice" do prepare_app - TestApp::Action.config.default_response_format = :csv - Admin::Action.config.default_response_format = :json + TestApp::Action.config.format :csv + Admin::Action.config.format :json - expect(Admin::Action.config.default_response_format).to eq :json + expect(Admin::Action.config.formats.values).to eq [:json] end end end describe "subclass in slice" do @@ -227,61 +225,60 @@ end it "applies default actions config from the app", :aggregate_failures do prepare_app - expect(Admin::Actions::Articles::Index.config.default_request_format).to eq :html - expect(Admin::Actions::Articles::Index.config.default_response_format).to eq :html + expect(Admin::Actions::Articles::Index.config.formats.values).to eq [] end it "applies actions config from the app" do - Hanami.app.config.actions.default_response_format = :json + Hanami.app.config.actions.format :json prepare_app - expect(Admin::Actions::Articles::Index.config.default_response_format).to eq :json + expect(Admin::Actions::Articles::Index.config.formats.values).to eq [:json] end it "applies actions config from the slice" do with_directory(@dir) do write "config/slices/admin.rb", <<~'RUBY' module Admin class Slice < Hanami::Slice - config.actions.default_response_format = :json + config.actions.format :json end end RUBY end prepare_app - expect(Admin::Actions::Articles::Index.config.default_response_format).to eq :json + expect(Admin::Actions::Articles::Index.config.formats.values).to eq [:json] end it "applies config from the slice base class" do prepare_app - Admin::Action.config.default_response_format = :json + Admin::Action.config.format :json - expect(Admin::Actions::Articles::Index.config.default_response_format).to eq :json + expect(Admin::Actions::Articles::Index.config.formats.values).to eq [:json] end it "prefers config from the slice base class over actions config from the slice" do with_directory(@dir) do write "config/slices/admin.rb", <<~'RUBY' module Admin class Slice < Hanami::Slice - config.actions.default_response_format = :csv + config.actions.format :csv end end RUBY end prepare_app - Admin::Action.config.default_response_format = :json + Admin::Action.config.format :json - expect(Admin::Actions::Articles::Index.config.default_response_format).to eq :json + expect(Admin::Actions::Articles::Index.config.formats.values).to eq [:json] end end end end