diff --git a/app/controllers/front_end_builds/application_controller.rb b/app/controllers/front_end_builds/application_controller.rb index 12e9290..3c908da 100644 --- a/app/controllers/front_end_builds/application_controller.rb +++ b/app/controllers/front_end_builds/application_controller.rb @@ -21,5 +21,21 @@ def error!(errors, status = :unprocessable_entity) respond_with_json({ errors: errors }, status: status) end + # Override this method using a decorator to customize what meta tags are + # injected into index.html. Most uses cases will probably want to copy + # these default values into their method and add to them rather than + # just replace them. + def feb_meta(app) + { + csrf_param: request_forgery_protection_token, + csrf_token: form_authenticity_token, + front_end_build_version: app.id, + front_end_build_params: use_params(:build_search_params).to_query, + front_end_build_url: front_end_builds_best_path( + use_params(:build_search_params).merge(format: :json) + ) + } + end + end end diff --git a/app/controllers/front_end_builds/bests_controller.rb b/app/controllers/front_end_builds/bests_controller.rb index aeaf544..9763a65 100644 --- a/app/controllers/front_end_builds/bests_controller.rb +++ b/app/controllers/front_end_builds/bests_controller.rb @@ -29,15 +29,7 @@ def show private def meta_tags - tags = { - csrf_param: request_forgery_protection_token, - csrf_token: form_authenticity_token, - front_end_build_version: @front_end.id, - front_end_build_params: use_params(:build_search_params).to_query, - front_end_build_url: front_end_builds_best_path( - use_params(:build_search_params).merge(format: :json) - ) - } + tags = feb_meta(@front_end) tags .map { |name, content| diff --git a/spec/controllers/front_end_builds/bests_controller_spec.rb b/spec/controllers/front_end_builds/bests_controller_spec.rb index b2d433f..e505d6f 100644 --- a/spec/controllers/front_end_builds/bests_controller_spec.rb +++ b/spec/controllers/front_end_builds/bests_controller_spec.rb @@ -62,7 +62,7 @@ module FrontEndBuilds expect(response.body).to match(latest.html) end - context "meta tags" do + context "default meta tags" do before(:each) do get :show, app_name: app.name, branch: 'master' expect(response).to be_success @@ -76,6 +76,19 @@ module FrontEndBuilds it { should match(/front-end-build-url/) } end + context "custom meta tags" do + before(:each) do + allow(controller).to receive(:feb_meta) + .and_return({ fake_meta_tag: 'custom' }) + get :show, app_name: app.name, branch: 'master' + expect(response).to be_success + end + + subject { response.body } + + it { should match(/fake-meta-tag/) } + end + it "should be 404 when nothing is found" do get :show, app_name: 'does-not-exist', branch: 'master' expect(response).to_not be_success