/ Published in: Ruby
Added partial, shared by both cobrand and dashboard views.busy/stale messages are dynamic ad can be customized for each of them independently.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
--partial-- #_messaging_options.html.haml .ugc-middle.partner-portal-middle .ugc-middle-content-block.ugc-middle-content-pp-block %p{:class => "cb-#{@backfilling}"} = @backfilling_message --views rendering partial-- #1. cobrand/index.html.haml - if (@backfilling == "stale" || @backfilling == "busy") = render :partial => 'partners/messaging_options' #2. dashboard/index.html.haml - if (@backfilling == "stale" || @backfilling == "busy") = render :partial => 'partners/messaging_options' - else .ugc-middle.partner-portal-middle ... .. --- controllers populates state and messages --- # dashboard_controller and cobrand_controller has the same code. @backfilling = AppConfig.value_of("fansnap.broker.backfill", "ok") # Change in message @ view can be achieved by editing here. @backfilling_message = if(@backfilling == 'busy') <<-eos The Partner Portal is not currently available while data is being updated. We will make the Partner Portal available again as soon as possible and we apologize for any inconvenience this may cause. Please contact us at if you have an urgent data request. Thank you for your patience. eos elsif(@backfilling == 'stale') <<-eos FanSnap is currently updating data in the portal from previous months. As a result, the information displayed may change when the update is complete. We apologize for any inconvenience this may cause. Please contact us at if you have an urgent data request. Thank you for your patience. eos --- #The same code at both controller can be moved to a helper and call it from a helper. This #approach would reduce our chances of customizing these messages specific to cobrand and #dashboard. #--- specs -- #I have created a shared example group which can be reused by both DashBoard(Broker) and #CoBrand. # This group should support both DashBoard and CoBrand shared_examples_for "Supporting back filling messages" do it "should have message as 'unavailable' when state is 'busy'" do @controller.stub!(:init_props)# No more pre-populating values AppConfig.merge({"fansnap.broker.backfill" => "busy"})# Setting the value to be busy AppConfig.merge({"fansnap.cobrand.backfill" => "busy"}) # Expecting that 'over riding properties through hierarchy' works fine. get :index, :channel_name => "fs" #Check if the view has proper message assigns[:backfilling_message].should =~ /The Partner Portal is not currently available/ end it "should have no message when state is 'ok'" do @controller.stub!(:init_props)# No more pre-populating values AppConfig.merge({"fansnap.broker.backfill" => "ok"})# Setting the value to be 'ok' AppConfig.merge({"fansnap.cobrand.backfill" => "ok"}) get :index, :channel_name => "fs" #Check if the view has no error message assigns[:backfilling_message].should be_nil end end and then dashboard and cobrand controllers uses it as; it_should_behave_like "Supporting back filling messages" #Both specs are green now.