<commit_before>require 'rails_helper'

RSpec.describe CardsController, type: :controller do
  let!(:card) { FactoryGirl.create :card }
  
  before :all do
      Rails.cache.clear
      WebMock.disable_net_connect!(:allow => %r{127.0.0.1:7055/hub/session})
  end

  describe "#index" do
    it "should increase card size and set referer to session" do
      canned_cards_answer = <<-END_OF_STRING
      {"cards":[{"id":13089288,"description":"Tyylik\u00e4s ja valoisa 4\/5 kerroksen kulmahuoneisto halutussa ja vehre\u00e4ss\u00e4 Vuoreksen uudessa kaupunginosassa","rooms":1,"roomConfiguration":"1h, kt, kph, parveke","price":"122\u00a0800\u00a0\u20ac","nextViewing":null,"images":{"wide":"http:\/\/asunnot.oikotie-static.edgesuite.net\/623*464\/142\/790\/wide\/142790490.jpg","thumb":"http:\/\/asunnot.oikotie-static.edgesuite.net\/215*161\/142\/790\/thumb_search\/142790490.jpg"},"newDevelopment":true,"published":"2016-04-30T12:18:09Z","size":32.5,"sizeLot":4700,"cardType":100,"contractType":1,"onlineOffer":null,"extraVisibility":null,"extraVisibilityString":null,"buildingData":{"address":"Koukkurannankatu 6 B 68","district":"Vuores","city":"Tampere","year":2016,"buildingType":1},"coordinates":{"latitude":61.43212,"longitude":23.80451},"brand":{"image":"http:\/\/asunnot.oikotie-static.edgesuite.net\/300*260\/143\/107\/company_image\/143107554.jpg","name":"Kiinteist\u00f6maailma, <NAME> LKV, Tampere","id":5013593},"priceChanged":null,"visits":0,"visits_weekly":0}],"found":51321,"start":1}
      END_OF_STRING
      canned_card_answer = <<-END_OF_STRING
      {"pageName":"property","notifcationPage":4,"card_id":"13089249","ad":{"ad_apartment_sell_id":13089249,"building_id":86872,"primary_address_id":86870,"user_id":null,"apartment_condition":2,"availability_date":null,"balcony":0,"building_override_build_year":1960,"building_override_lift":0,"building_override_sauna":0,"building_rights":null,"contract_type":1,"debt_payable":null,"floor":1,"floor_count":null,"floor_location":null,"habitation_type":1,"igglo_id":"9528212","is_rented":null,"kitchen":null,"new_development":0,"new_development_status":null,"price":239000,"published":"2016-05-15 14:53:48","published_search_sort":"2016-05-15 14:53:48","first_showing":null,"room_configuration":"2 h, kk ja psh","rooms":2,"sauna":0,"sauna_charge":null,"sauna_charge_unit":null,"sell_status":3,"shore_ownership_type":null,"shore_type":null,"size":37,"size_office":null,"source_type":1,"status":1,"title":"Ainutlaatuinen rivitalokoti rauhallisella alueella","usage_fee":null},"adExtra":{"ad_apartment_sell_id":13089249,"private_vendor_ad_id":null,"address_info":"Risto Rytin tie 19","area_description_info":null,"attachments_info":null,"attachments_url":null,"antenna_system_info":"kaapeli-tv","apartment_number":null,"availability_info":"sopimuksen mukaan","balcony_info":null,"bathroom_appliance_info":"Varustus: pesukoneliit\u00e4nt\u00e4, wc, suihku, peilikaappi.","build_year_info":"1960","building_extra_info":null,"building_override_apartment_house_company":null,"building_override_apartment_sizes_total":1237,"building_override_apartments":11,"building_override_building_material_info":"puu, tiili","building_override_building_plan_info":"Kaavamuutoksia vireill\u00e4. Lis\u00e4tietoa Helsingin kaupunki.","building_override_building_plan_situation":"Asemakaava","building_override_building_subtype":null,"building_override_building_type":2,"building_override_business_premises":null,"building_override_business_premises_sizes_total":null,"building_override_core_type":null,"building_override_exterior_material_info":null,"building_override_energy_class":"F2007","building_override_energy_flag":1,"building_override_floors":1,"building_override_heating_method":null,"building_override_location_type":null,"building_override_lot_ownership":1,"building_override_lot_ownership_info":null,"building_override_lot_rent_contract_until":null,"building_override_lot_size":null,"building_override_price_max":null,"building_override_price_min":null,"building_override_renovation_balcony":null,"building_override_renovation_facade":null,"building_override_renovation_other":null,"building_override_renovation_pipe":null,"building_override_renovation_roof":null,"building_override_renovation_window":null,"building_override_renovation_yard":null,"building_override_roof_material_info":"Pelti","building_override_roof_type_info":"Tasa","building_override_rooms_max":null,"building_override_rooms_min":null,"building_override_size_max":null,"building_override_size_min":null,"building_override_superintendent":"Juha Korpi Lapinrinne 2, 00180 Helsinki Is\u00e4nn\u00f6intipalvelu Isarvo Oy P. 0400 153 789","building_override_technical_information":null,"building_override_total_size":null,"building_override_transfer_limitations":null,"building_override_usage":null,"building_override_ventilation":null,"cable_tv_charge":null,"cable_tv_charge_unit":null,"car_storage_info":null,"car_storage_unit":null,"car_storage_cost":null,"buyer_costs":null,"building_rights_unit":null,"comment":null,"condition_inspection_info":null,"common_areas_info":"v\u00e4est\u00f6nsuoja.","completion_time":null,"condition_info":"Hyv\u00e4","connections_info":null,"contact_email":"<EMAIL>","contact_email_2":null,"contact_email_3":null,"contact_address":null,"contact_name":"<NAME>","contact_person_picture_url":"http:\/\/img.cromet.fi\/itemimages\/suppliercont\/www\/209.12339\/img338089823748153121.jpg","contact_phone":"040 680 7709","contact_show":null,"contract_date":null,"description":"Ainutlaatuinen rivitalokoti rauhallisella alueella.Hyvin hoidettu taloyhti\u00f6 jossa juuri tehty ikkuna- katto- ja julkisivuremontti.Valoisa koti odottaa uutta asukasta sopii erinomaisesti vaikka ensiasunnoksi tule ja tutustu.Esittelyt <NAME>ainen 040 680 7709 tai <EMAIL>.Oma koti viel\u00e4 myym\u00e4tt\u00e4? Pyyd\u00e4 minut maksuttomalle arvioik\u00e4ynnille niin katsomme kotinne arvon.","description_supplementary":null,"direction_info":null,"direction_window_info":null,"driving_instructions":null,"electricity_consumption_average":null,"electricity_consumption_annual":null,"electricity_consumption_unit":null,"encumbrances_info":null,"estate_ownership_type":0,"estate_premises_and_profits":null,"estate_tax":null,"financial_fee":113.77,"financing_offer_1_fee":null,"financing_offer_1_percentage":null,"financing_offer_1_price":null,"financing_offer_2_fee":null,"financing_offer_2_percentage":null,"financing_offer_2_price":null,"floor_location":"1\/1","floor_material_info":"Lattia: Keitti\u00f6ss\u00e4: laatta. Pesutiloissa: laatta. Olohuoneessa: laminaatti. Makuuhuoneessa: laminaatti. Sein\u00e4t: Keitti\u00f6ss\u00e4: kaakeli, maalattu. Pesutiloissa: kaakeli. Olohuoneessa: tapetti. Makuuhuoneessa: tapetti. Sein\u00e4materiaalien kuvaus: Makuuhuoneen yksi sein\u00e4 \u00e4\u00e4nieristett\u00e4v\u00e4.","foundation_info":null,"grounds_info":null,"heating_cost":null,"heating_info":"kauko","hobby_possibilities":null,"honoring_clause":"ei lunastusoikeutta","housing_company_name":"<NAME>","hunting_right":null,"kitchen_appliance_info":"Liesi: s\u00e4hk\u00f6liesi. Ty\u00f6tasot: puu. Kylm\u00e4s\u00e4ilytys: j\u00e4\u00e4kaappi\/pakastin. Varustus: liesituuletin.","lease_holder":null,"lift_info":null,"link_text":null,"living_area_info":null,"living_area_type":null,"lot_fee":null,"lot_rent":null,"lot_repurchase_price":null,"inquiries":null,"maintenance_fee":170,"management_charge":283.77,"management_method_info":"Asukkaat.","mode_of_financing":null,"more_info_text":null,"mortgages_info":null,"municipal_development_info":null,"new_apartment_reserved":null,"other_appliances":null,"other_buildings_info":null,"other_fees_info":null,"other_premises":null,"ownership_type":null,"parking_fee":null,"parking_space_info":"autotalleja 5, piha-autopaikkoja 15,","partner_paper":0,"price_sell":218854.92,"publish_purchase_price":null,"real_estate_id":null,"renovation_bathroom":null,"renovation_future_info":"L\u00e4hiaikojen korjaukset: Viem\u00e4reiden kunnostus pinnoittamalla, mik\u00e4li hanketta selvitett\u00e4ess\u00e4 todetaan mahdolliseksi.","renovation_info":"Autotallien katto v.2000, Kaukol\u00e4mp\u00f6keskus v.2002, LV+KV putket v. 2004. Pihan asfaltointi v.2012. Katto- julkisivu- ja ikkunaremontti. 2014-2015","renovation_kitchen":null,"renovation_other":null,"rent_income_monthly":null,"rent_term_info":null,"rented":null,"sanitation_info":null,"road_costs":null,"sauna_fee":null,"sauna_info":null,"sell_comments":null,"sell_date":null,"sell_type":null,"sender_node":"ext022","services_info":null,"sewage_and_water_info":null,"sewer_system_info":null,"share_of_debt_70":null,"share_of_debt_85":null,"share_of_liabilities":null,"shore_direction":null,"shore_length":null,"shore_info":null,"shores_description_info":null,"show_lead_form":null,"size_floor":null,"size_total":37,"storage_info":null,"use_of_water":null,"vista_info":null,"virtual_presentation_text":null,"virtual_presentation_url":null,"water_fee":22,"water_fee_info":"22 EUR\/hl\u00f6\/kk","waters":null,"waters_info":null,"yard_direction":null,"yard_info":null,"district_info":"Kulosaari","city_info":"Helsinki","zip_code_info":"00570"},"additionalInfo":{"card_id":13089249,"apartment_city_plan_id":null,"appliances_internet":null,"appliances_bedroom":null,"appliances_livingroom":null,"appliances_nonincluded":null,"appliances_other":null,"appliances_tv":null,"background_image":null,"background_color":null,"city_area_id":null,"contact_person_title":null,"contact_person_rating":null,"contact_person_degrees":null,"contact_person_some_url":null,"contact_person_some":null,"estate_name":null,"estate_info":null,"floor_bathroom":null,"floor_bedroom":null,"floor_kitchen":null,"floor_livingroom":null,"other_materials":null,"other_spaces":null,"postal_area_id":null,"parking_space_type":null,"parking_space_heated":null,"parking_space_electricity":null,"redemption_price":null,"shore_direction":null,"shore_length":null,"site_rent_end":null,"start_of_use_year":null,"terrace":null,"ventilation_system":null,"vrk_id":null,"vrk_apartment_id":null,"wall_bathroom":null,"wall_bedroom":null,"wall_kitchen":null,"wall_livingroom":null},"medias":[{"media_id":149738340,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738343,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738346,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738349,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738352,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738355,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738358,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738361,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738364,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738367,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1}],"building":{"building_id":86872,"building_class":1,"primary_address_id":86870,"build_year":1960,"building_type":2,"location_type":1,"floors":2,"lift":0,"sauna":1,"apartments":11,"size_min":37,"size_max":190,"status":1,"vrk_id":"1001912305"},"district":{"district_id":1680,"city_id":64,"name":"Kulosaari","status":1},"address":{"address_id":86870,"street_id":75100,"street_number":"19","building_letter":null,"zip_code_id":14731,"status":1},"city":{"city_id":64,"county_id":2,"name":"Helsinki","status":1},"street":{"street_id":75100,"city_id":64,"name":"<NAME> tie","status":1,"name_swe":"<NAME> v\u00e4g"},"company":{"company_id":5014209,"oikotie_company_id":40777},"oikotieCompany":{"ID":40777,"MARKETING_NAME":"Huom! | Kahdeksas p\u00e4iv\u00e4 Oy, Hitsaajankatu 24","EXTERNAL_ID":"KIVI-12339","TRADE_REGISTRY_NUMBER":"2044327-1","COMPANY_STATUS":"ACTIVE","COMPANY_TYPE":"REAL ESTATE AGENT","STREET_ADDRESS":"Hitsaajankatu 24","ZIP_CODE":"00810","CITY":"Helsinki","COUNTY":"Uusimaa","IS_FOREIGN_COMPANY":0,"EMAIL_ADDRESS":"<EMAIL>","LEAD_EMAIL_ADDRESS":null,"PHONE_NUMBER":"020 780 3950","FAX_NUMBER":null,"MAP_COORDINATE_LAT":"3384878","MAP_COORDINATE_LON":"6676668","PARENT_COMPANY_ID":91925,"PARENT_COMPANY_NAME":"Huom!","CHANGED_DATE":"2016-04-08 09:16:27","HAS_LISTLOGO":0,"HAS_CONTRACT":1,"HAS_ADGUARANTEE":1,"IS_SELF_REGISTERED":0,"IS_CREDITABLE":1,"HAS_FREESPEE":0,"SELLER_ID":7},"coordinates":{"card_id":86872,"latitude":60.186691279801,"longitude":25.017185247395},"viewings":[],"logo1":"http:\/\/asunnot.oikotie-static.edgesuite.net\/240*40\/110\/151\/logo\/110151119.jpg","logo2":"http:\/\/asunnot.oikotie-static.edgesuite.net\/240*40\/110\/151\/logo\/110151119.jpg","zipCode":{"zip_code_id":14731,"city_id":64,"zip_code":"00570","name":"Helsinki","status":1},"notifications":[]}
      END_OF_STRING

      stub_request(:get, "https://asunnot.oikotie.fi/api/cards?cardType=100&limit=12&offset=0&price%5Bmin%5D=1000000").to_return(body: canned_cards_answer, headers: { 'Content-Type' => "text/json" })
      stub_request(:get, "https://asunnot.oikotie.fi/myytavat-asunnot/13089288?format=json").to_return(body: canned_card_answer, headers: { 'Content-Type' => "text/json" })

      expect {
          get :index
        }.to change(Card, :count).by(1)

      expect(session[:referrer]).to eq('http://test.host/')
    end

    it "should on duplicate call use cache and not insert new cards" do
      canned_cards_answer = <<-END_OF_STRING
      {"cards":[{"id":13089288,"description":"Tyylik\u00e4s ja valoisa 4\/5 kerroksen kulmahuoneisto halutussa ja vehre\u00e4ss\u00e4 Vuoreksen uudessa kaupunginosassa","rooms":1,"roomConfiguration":"1h, kt, kph, parveke","price":"122\u00a0800\u00a0\u20ac","nextViewing":null,"images":{"wide":"http:\/\/asunnot.oikotie-static.edgesuite.net\/623*464\/142\/790\/wide\/142790490.jpg","thumb":"http:\/\/asunnot.oikotie-static.edgesuite.net\/215*161\/142\/790\/thumb_search\/142790490.jpg"},"newDevelopment":true,"published":"2016-04-30T12:18:09Z","size":32.5,"sizeLot":4700,"cardType":100,"contractType":1,"onlineOffer":null,"extraVisibility":null,"extraVisibilityString":null,"buildingData":{"address":"Koukkurannankatu 6 B 68","district":"Vuores","city":"Tampere","year":2016,"buildingType":1},"coordinates":{"latitude":61.43212,"longitude":23.80451},"brand":{"image":"http:\/\/asunnot.oikotie-static.edgesuite.net\/300*260\/143\/107\/company_image\/143107554.jpg","name":"Kiinteist\u00f6maailma, Koskikeskuk<NAME> Oy LKV, Tampere","id":5013593},"priceChanged":null,"visits":0,"visits_weekly":0}],"found":51321,"start":1}
      END_OF_STRING
      canned_card_answer = <<-END_OF_STRING
      {"pageName":"property","notifcationPage":4,"card_id":"13089249","ad":{"ad_apartment_sell_id":13089249,"building_id":86872,"primary_address_id":86870,"user_id":null,"apartment_condition":2,"availability_date":null,"balcony":0,"building_override_build_year":1960,"building_override_lift":0,"building_override_sauna":0,"building_rights":null,"contract_type":1,"debt_payable":null,"floor":1,"floor_count":null,"floor_location":null,"habitation_type":1,"igglo_id":"9528212","is_rented":null,"kitchen":null,"new_development":0,"new_development_status":null,"price":239000,"published":"2016-05-15 14:53:48","published_search_sort":"2016-05-15 14:53:48","first_showing":null,"room_configuration":"2 h, kk ja psh","rooms":2,"sauna":0,"sauna_charge":null,"sauna_charge_unit":null,"sell_status":3,"shore_ownership_type":null,"shore_type":null,"size":37,"size_office":null,"source_type":1,"status":1,"title":"Ainutlaatuinen rivitalokoti rauhallisella alueella","usage_fee":null},"adExtra":{"ad_apartment_sell_id":13089249,"private_vendor_ad_id":null,"address_info":"Risto Rytin tie 19","area_description_info":null,"attachments_info":null,"attachments_url":null,"antenna_system_info":"kaapeli-tv","apartment_number":null,"availability_info":"sopimuksen mukaan","balcony_info":null,"bathroom_appliance_info":"Varustus: pesukoneliit\u00e4nt\u00e4, wc, suihku, peilikaappi.","build_year_info":"1960","building_extra_info":null,"building_override_apartment_house_company":null,"building_override_apartment_sizes_total":1237,"building_override_apartments":11,"building_override_building_material_info":"puu, tiili","building_override_building_plan_info":"Kaavamuutoksia vireill\u00e4. Lis\u00e4tietoa Helsingin kaupunki.","building_override_building_plan_situation":"Asemakaava","building_override_building_subtype":null,"building_override_building_type":2,"building_override_business_premises":null,"building_override_business_premises_sizes_total":null,"building_override_core_type":null,"building_override_exterior_material_info":null,"building_override_energy_class":"F2007","building_override_energy_flag":1,"building_override_floors":1,"building_override_heating_method":null,"building_override_location_type":null,"building_override_lot_ownership":1,"building_override_lot_ownership_info":null,"building_override_lot_rent_contract_until":null,"building_override_lot_size":null,"building_override_price_max":null,"building_override_price_min":null,"building_override_renovation_balcony":null,"building_override_renovation_facade":null,"building_override_renovation_other":null,"building_override_renovation_pipe":null,"building_override_renovation_roof":null,"building_override_renovation_window":null,"building_override_renovation_yard":null,"building_override_roof_material_info":"Pelti","building_override_roof_type_info":"Tasa","building_override_rooms_max":null,"building_override_rooms_min":null,"building_override_size_max":null,"building_override_size_min":null,"building_override_superintendent":"Ju<NAME> 2, 00180 Helsinki Is\u00e4nn\u00f6intipalvelu Isarvo Oy P. 0400 153 789","building_override_technical_information":null,"building_override_total_size":null,"building_override_transfer_limitations":null,"building_override_usage":null,"building_override_ventilation":null,"cable_tv_charge":null,"cable_tv_charge_unit":null,"car_storage_info":null,"car_storage_unit":null,"car_storage_cost":null,"buyer_costs":null,"building_rights_unit":null,"comment":null,"condition_inspection_info":null,"common_areas_info":"v\u00e4est\u00f6nsuoja.","completion_time":null,"condition_info":"Hyv\u00e4","connections_info":null,"contact_email":"<EMAIL>","contact_email_2":null,"contact_email_3":null,"contact_address":null,"contact_name":"<NAME>","contact_person_picture_url":"http:\/\/img.cromet.fi\/itemimages\/suppliercont\/www\/209.12339\/img338089823748153121.jpg","contact_phone":"040 680 7709","contact_show":null,"contract_date":null,"description":"Ainutlaatuinen rivitalokoti rauhallisella alueella.Hyvin hoidettu taloyhti\u00f6 jossa juuri tehty ikkuna- katto- ja julkisivuremontti.Valoisa koti odottaa uutta asukasta sopii erinomaisesti vaikka ensiasunnoksi tule ja tutustu.Esittelyt <NAME>en 040 680 7709 tai <EMAIL>.Oma koti viel\u00e4 myym\u00e4tt\u00e4? Pyyd\u00e4 minut maksuttomalle arvioik\u00e4ynnille niin katsomme kotinne arvon.","description_supplementary":null,"direction_info":null,"direction_window_info":null,"driving_instructions":null,"electricity_consumption_average":null,"electricity_consumption_annual":null,"electricity_consumption_unit":null,"encumbrances_info":null,"estate_ownership_type":0,"estate_premises_and_profits":null,"estate_tax":null,"financial_fee":113.77,"financing_offer_1_fee":null,"financing_offer_1_percentage":null,"financing_offer_1_price":null,"financing_offer_2_fee":null,"financing_offer_2_percentage":null,"financing_offer_2_price":null,"floor_location":"1\/1","floor_material_info":"Lattia: Keitti\u00f6ss\u00e4: laatta. Pesutiloissa: laatta. Olohuoneessa: laminaatti. Makuuhuoneessa: laminaatti. Sein\u00e4t: Keitti\u00f6ss\u00e4: kaakeli, maalattu. Pesutiloissa: kaakeli. Olohuoneessa: tapetti. Makuuhuoneessa: tapetti. Sein\u00e4materiaalien kuvaus: Makuuhuoneen yksi sein\u00e4 \u00e4\u00e4nieristett\u00e4v\u00e4.","foundation_info":null,"grounds_info":null,"heating_cost":null,"heating_info":"kauko","hobby_possibilities":null,"honoring_clause":"ei lunastusoikeutta","housing_company_name":"<NAME>","hunting_right":null,"kitchen_appliance_info":"Liesi: s\u00e4hk\u00f6liesi. Ty\u00f6tasot: puu. Kylm\u00e4s\u00e4ilytys: j\u00e4\u00e4kaappi\/pakastin. Varustus: liesituuletin.","lease_holder":null,"lift_info":null,"link_text":null,"living_area_info":null,"living_area_type":null,"lot_fee":null,"lot_rent":null,"lot_repurchase_price":null,"inquiries":null,"maintenance_fee":170,"management_charge":283.77,"management_method_info":"Asukkaat.","mode_of_financing":null,"more_info_text":null,"mortgages_info":null,"municipal_development_info":null,"new_apartment_reserved":null,"other_appliances":null,"other_buildings_info":null,"other_fees_info":null,"other_premises":null,"ownership_type":null,"parking_fee":null,"parking_space_info":"autotalleja 5, piha-autopaikkoja 15,","partner_paper":0,"price_sell":218854.92,"publish_purchase_price":null,"real_estate_id":null,"renovation_bathroom":null,"renovation_future_info":"L\u00e4hiaikojen korjaukset: Viem\u00e4reiden kunnostus pinnoittamalla, mik\u00e4li hanketta selvitett\u00e4ess\u00e4 todetaan mahdolliseksi.","renovation_info":"Autotallien katto v.2000, Kaukol\u00e4mp\u00f6keskus v.2002, LV+KV putket v. 2004. Pihan asfaltointi v.2012. Katto- julkisivu- ja ikkunaremontti. 2014-2015","renovation_kitchen":null,"renovation_other":null,"rent_income_monthly":null,"rent_term_info":null,"rented":null,"sanitation_info":null,"road_costs":null,"sauna_fee":null,"sauna_info":null,"sell_comments":null,"sell_date":null,"sell_type":null,"sender_node":"ext022","services_info":null,"sewage_and_water_info":null,"sewer_system_info":null,"share_of_debt_70":null,"share_of_debt_85":null,"share_of_liabilities":null,"shore_direction":null,"shore_length":null,"shore_info":null,"shores_description_info":null,"show_lead_form":null,"size_floor":null,"size_total":37,"storage_info":null,"use_of_water":null,"vista_info":null,"virtual_presentation_text":null,"virtual_presentation_url":null,"water_fee":22,"water_fee_info":"22 EUR\/hl\u00f6\/kk","waters":null,"waters_info":null,"yard_direction":null,"yard_info":null,"district_info":"Kulosaari","city_info":"Helsinki","zip_code_info":"00570"},"additionalInfo":{"card_id":13089249,"apartment_city_plan_id":null,"appliances_internet":null,"appliances_bedroom":null,"appliances_livingroom":null,"appliances_nonincluded":null,"appliances_other":null,"appliances_tv":null,"background_image":null,"background_color":null,"city_area_id":null,"contact_person_title":null,"contact_person_rating":null,"contact_person_degrees":null,"contact_person_some_url":null,"contact_person_some":null,"estate_name":null,"estate_info":null,"floor_bathroom":null,"floor_bedroom":null,"floor_kitchen":null,"floor_livingroom":null,"other_materials":null,"other_spaces":null,"postal_area_id":null,"parking_space_type":null,"parking_space_heated":null,"parking_space_electricity":null,"redemption_price":null,"shore_direction":null,"shore_length":null,"site_rent_end":null,"start_of_use_year":null,"terrace":null,"ventilation_system":null,"vrk_id":null,"vrk_apartment_id":null,"wall_bathroom":null,"wall_bedroom":null,"wall_kitchen":null,"wall_livingroom":null},"medias":[{"media_id":149738340,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738343,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738346,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738349,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738352,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738355,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738358,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738361,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738364,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738367,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1}],"building":{"building_id":86872,"building_class":1,"primary_address_id":86870,"build_year":1960,"building_type":2,"location_type":1,"floors":2,"lift":0,"sauna":1,"apartments":11,"size_min":37,"size_max":190,"status":1,"vrk_id":"1001912305"},"district":{"district_id":1680,"city_id":64,"name":"Kulosaari","status":1},"address":{"address_id":86870,"street_id":75100,"street_number":"19","building_letter":null,"zip_code_id":14731,"status":1},"city":{"city_id":64,"county_id":2,"name":"Helsinki","status":1},"street":{"street_id":75100,"city_id":64,"name":"<NAME>","status":1,"name_swe":"<NAME> v\u00e4g"},"company":{"company_id":5014209,"oikotie_company_id":40777},"oikotieCompany":{"ID":40777,"MARKETING_NAME":"Huom! | Kahdeksas p\u00e4iv\u00e4 Oy, Hitsaajankatu 24","EXTERNAL_ID":"KIVI-12339","TRADE_REGISTRY_NUMBER":"2044327-1","COMPANY_STATUS":"ACTIVE","COMPANY_TYPE":"REAL ESTATE AGENT","STREET_ADDRESS":"Hitsaajankatu 24","ZIP_CODE":"00810","CITY":"Helsinki","COUNTY":"Uusimaa","IS_FOREIGN_COMPANY":0,"EMAIL_ADDRESS":"<EMAIL>","LEAD_EMAIL_ADDRESS":null,"PHONE_NUMBER":"020 780 3950","FAX_NUMBER":null,"MAP_COORDINATE_LAT":"3384878","MAP_COORDINATE_LON":"6676668","PARENT_COMPANY_ID":91925,"PARENT_COMPANY_NAME":"Huom!","CHANGED_DATE":"2016-04-08 09:16:27","HAS_LISTLOGO":0,"HAS_CONTRACT":1,"HAS_ADGUARANTEE":1,"IS_SELF_REGISTERED":0,"IS_CREDITABLE":1,"HAS_FREESPEE":0,"SELLER_ID":7},"coordinates":{"card_id":86872,"latitude":60.186691279801,"longitude":25.017185247395},"viewings":[],"logo1":"http:\/\/asunnot.oikotie-static.edgesuite.net\/240*40\/110\/151\/logo\/110151119.jpg","logo2":"http:\/\/asunnot.oikotie-static.edgesuite.net\/240*40\/110\/151\/logo\/110151119.jpg","zipCode":{"zip_code_id":14731,"city_id":64,"zip_code":"00570","name":"Helsinki","status":1},"notifications":[]}
      END_OF_STRING

      stub_request(:get, "https://asunnot.oikotie.fi/api/cards?cardType=100&limit=12&offset=0&price%5Bmin%5D=1000000").to_return(body: canned_cards_answer, headers: { 'Content-Type' => "text/json" })
      stub_request(:get, "https://asunnot.oikotie.fi/myytavat-asunnot/13089288?format=json").to_return(body: canned_card_answer, headers: { 'Content-Type' => "text/json" })

      expect {
          get :index
        }.to change(Card, :count).by(1)

      expect {
          get :index
        }.to change(Card, :count).by(0)
    end
  end

  describe "#show" do
    context "card without relations" do
      it "assigns the requested card as @card" do
        get :show, {:id => card.to_param}
        expect(assigns(:card)).to eq(card)
      end
    end

    context "card with feature relations" do
      let!(:feature) { FactoryGirl.create :feature, card: card }

      it "assigns the requested card as @card" do
        get :show, {:id => card.to_param}
        expect(assigns(:card)).to eq(card)
      end
    end

    it "should use session referrer if set" do
      session[:referrer] = 'http://test.host?limit=100'
      get :show, {:id => card.to_param}
    end
  end
end
<commit_msg>Fixed issue with rails cache in testing<commit_after>require 'rails_helper'

RSpec.describe CardsController, type: :controller do
  let!(:card) { FactoryGirl.create :card }
  
  before :all do
      WebMock.disable_net_connect!(:allow => %r{127.0.0.1:7055/hub/session})
  end

  after :all do
    Rails.cache.clear 
  end

  describe "#index" do
    it "should increase card size and set referer to session" do
      canned_cards_answer = <<-END_OF_STRING
      {"cards":[{"id":13089288,"description":"Tyylik\u00e4s ja valoisa 4\/5 kerroksen kulmahuoneisto halutussa ja vehre\u00e4ss\u00e4 Vuoreksen uudessa kaupunginosassa","rooms":1,"roomConfiguration":"1h, kt, kph, parveke","price":"122\u00a0800\u00a0\u20ac","nextViewing":null,"images":{"wide":"http:\/\/asunnot.oikotie-static.edgesuite.net\/623*464\/142\/790\/wide\/142790490.jpg","thumb":"http:\/\/asunnot.oikotie-static.edgesuite.net\/215*161\/142\/790\/thumb_search\/142790490.jpg"},"newDevelopment":true,"published":"2016-04-30T12:18:09Z","size":32.5,"sizeLot":4700,"cardType":100,"contractType":1,"onlineOffer":null,"extraVisibility":null,"extraVisibilityString":null,"buildingData":{"address":"Koukkurannankatu 6 B 68","district":"Vuores","city":"Tampere","year":2016,"buildingType":1},"coordinates":{"latitude":61.43212,"longitude":23.80451},"brand":{"image":"http:\/\/asunnot.oikotie-static.edgesuite.net\/300*260\/143\/107\/company_image\/143107554.jpg","name":"Kiinteist\u00f6maailma, <NAME> LKV, Tampere","id":5013593},"priceChanged":null,"visits":0,"visits_weekly":0}],"found":51321,"start":1}
      END_OF_STRING
      canned_card_answer = <<-END_OF_STRING
      {"pageName":"property","notifcationPage":4,"card_id":"13089249","ad":{"ad_apartment_sell_id":13089249,"building_id":86872,"primary_address_id":86870,"user_id":null,"apartment_condition":2,"availability_date":null,"balcony":0,"building_override_build_year":1960,"building_override_lift":0,"building_override_sauna":0,"building_rights":null,"contract_type":1,"debt_payable":null,"floor":1,"floor_count":null,"floor_location":null,"habitation_type":1,"igglo_id":"9528212","is_rented":null,"kitchen":null,"new_development":0,"new_development_status":null,"price":239000,"published":"2016-05-15 14:53:48","published_search_sort":"2016-05-15 14:53:48","first_showing":null,"room_configuration":"2 h, kk ja psh","rooms":2,"sauna":0,"sauna_charge":null,"sauna_charge_unit":null,"sell_status":3,"shore_ownership_type":null,"shore_type":null,"size":37,"size_office":null,"source_type":1,"status":1,"title":"Ainutlaatuinen rivitalokoti rauhallisella alueella","usage_fee":null},"adExtra":{"ad_apartment_sell_id":13089249,"private_vendor_ad_id":null,"address_info":"Risto Rytin tie 19","area_description_info":null,"attachments_info":null,"attachments_url":null,"antenna_system_info":"kaapeli-tv","apartment_number":null,"availability_info":"sopimuksen mukaan","balcony_info":null,"bathroom_appliance_info":"Varustus: pesukoneliit\u00e4nt\u00e4, wc, suihku, peilikaappi.","build_year_info":"1960","building_extra_info":null,"building_override_apartment_house_company":null,"building_override_apartment_sizes_total":1237,"building_override_apartments":11,"building_override_building_material_info":"puu, tiili","building_override_building_plan_info":"Kaavamuutoksia vireill\u00e4. Lis\u00e4tietoa Helsingin kaupunki.","building_override_building_plan_situation":"Asemakaava","building_override_building_subtype":null,"building_override_building_type":2,"building_override_business_premises":null,"building_override_business_premises_sizes_total":null,"building_override_core_type":null,"building_override_exterior_material_info":null,"building_override_energy_class":"F2007","building_override_energy_flag":1,"building_override_floors":1,"building_override_heating_method":null,"building_override_location_type":null,"building_override_lot_ownership":1,"building_override_lot_ownership_info":null,"building_override_lot_rent_contract_until":null,"building_override_lot_size":null,"building_override_price_max":null,"building_override_price_min":null,"building_override_renovation_balcony":null,"building_override_renovation_facade":null,"building_override_renovation_other":null,"building_override_renovation_pipe":null,"building_override_renovation_roof":null,"building_override_renovation_window":null,"building_override_renovation_yard":null,"building_override_roof_material_info":"Pelti","building_override_roof_type_info":"Tasa","building_override_rooms_max":null,"building_override_rooms_min":null,"building_override_size_max":null,"building_override_size_min":null,"building_override_superintendent":"Juha Korpi Lapinrinne 2, 00180 Helsinki Is\u00e4nn\u00f6intipalvelu Isarvo Oy P. 0400 153 789","building_override_technical_information":null,"building_override_total_size":null,"building_override_transfer_limitations":null,"building_override_usage":null,"building_override_ventilation":null,"cable_tv_charge":null,"cable_tv_charge_unit":null,"car_storage_info":null,"car_storage_unit":null,"car_storage_cost":null,"buyer_costs":null,"building_rights_unit":null,"comment":null,"condition_inspection_info":null,"common_areas_info":"v\u00e4est\u00f6nsuoja.","completion_time":null,"condition_info":"Hyv\u00e4","connections_info":null,"contact_email":"<EMAIL>","contact_email_2":null,"contact_email_3":null,"contact_address":null,"contact_name":"<NAME>","contact_person_picture_url":"http:\/\/img.cromet.fi\/itemimages\/suppliercont\/www\/209.12339\/img338089823748153121.jpg","contact_phone":"040 680 7709","contact_show":null,"contract_date":null,"description":"Ainutlaatuinen rivitalokoti rauhallisella alueella.Hyvin hoidettu taloyhti\u00f6 jossa juuri tehty ikkuna- katto- ja julkisivuremontti.Valoisa koti odottaa uutta asukasta sopii erinomaisesti vaikka ensiasunnoksi tule ja tutustu.Esittelyt <NAME>ainen 040 680 7709 tai <EMAIL>.Oma koti viel\u00e4 myym\u00e4tt\u00e4? Pyyd\u00e4 minut maksuttomalle arvioik\u00e4ynnille niin katsomme kotinne arvon.","description_supplementary":null,"direction_info":null,"direction_window_info":null,"driving_instructions":null,"electricity_consumption_average":null,"electricity_consumption_annual":null,"electricity_consumption_unit":null,"encumbrances_info":null,"estate_ownership_type":0,"estate_premises_and_profits":null,"estate_tax":null,"financial_fee":113.77,"financing_offer_1_fee":null,"financing_offer_1_percentage":null,"financing_offer_1_price":null,"financing_offer_2_fee":null,"financing_offer_2_percentage":null,"financing_offer_2_price":null,"floor_location":"1\/1","floor_material_info":"Lattia: Keitti\u00f6ss\u00e4: laatta. Pesutiloissa: laatta. Olohuoneessa: laminaatti. Makuuhuoneessa: laminaatti. Sein\u00e4t: Keitti\u00f6ss\u00e4: kaakeli, maalattu. Pesutiloissa: kaakeli. Olohuoneessa: tapetti. Makuuhuoneessa: tapetti. Sein\u00e4materiaalien kuvaus: Makuuhuoneen yksi sein\u00e4 \u00e4\u00e4nieristett\u00e4v\u00e4.","foundation_info":null,"grounds_info":null,"heating_cost":null,"heating_info":"kauko","hobby_possibilities":null,"honoring_clause":"ei lunastusoikeutta","housing_company_name":"Asunto <NAME>","hunting_right":null,"kitchen_appliance_info":"Liesi: s\u00e4hk\u00f6liesi. Ty\u00f6tasot: puu. Kylm\u00e4s\u00e4ilytys: j\u00e4\u00e4kaappi\/pakastin. Varustus: liesituuletin.","lease_holder":null,"lift_info":null,"link_text":null,"living_area_info":null,"living_area_type":null,"lot_fee":null,"lot_rent":null,"lot_repurchase_price":null,"inquiries":null,"maintenance_fee":170,"management_charge":283.77,"management_method_info":"Asukkaat.","mode_of_financing":null,"more_info_text":null,"mortgages_info":null,"municipal_development_info":null,"new_apartment_reserved":null,"other_appliances":null,"other_buildings_info":null,"other_fees_info":null,"other_premises":null,"ownership_type":null,"parking_fee":null,"parking_space_info":"autotalleja 5, piha-autopaikkoja 15,","partner_paper":0,"price_sell":218854.92,"publish_purchase_price":null,"real_estate_id":null,"renovation_bathroom":null,"renovation_future_info":"L\u00e4hiaikojen korjaukset: Viem\u00e4reiden kunnostus pinnoittamalla, mik\u00e4li hanketta selvitett\u00e4ess\u00e4 todetaan mahdolliseksi.","renovation_info":"Autotallien katto v.2000, Kaukol\u00e4mp\u00f6keskus v.2002, LV+KV putket v. 2004. Pihan asfaltointi v.2012. Katto- julkisivu- ja ikkunaremontti. 2014-2015","renovation_kitchen":null,"renovation_other":null,"rent_income_monthly":null,"rent_term_info":null,"rented":null,"sanitation_info":null,"road_costs":null,"sauna_fee":null,"sauna_info":null,"sell_comments":null,"sell_date":null,"sell_type":null,"sender_node":"ext022","services_info":null,"sewage_and_water_info":null,"sewer_system_info":null,"share_of_debt_70":null,"share_of_debt_85":null,"share_of_liabilities":null,"shore_direction":null,"shore_length":null,"shore_info":null,"shores_description_info":null,"show_lead_form":null,"size_floor":null,"size_total":37,"storage_info":null,"use_of_water":null,"vista_info":null,"virtual_presentation_text":null,"virtual_presentation_url":null,"water_fee":22,"water_fee_info":"22 EUR\/hl\u00f6\/kk","waters":null,"waters_info":null,"yard_direction":null,"yard_info":null,"district_info":"Kulosaari","city_info":"Helsinki","zip_code_info":"00570"},"additionalInfo":{"card_id":13089249,"apartment_city_plan_id":null,"appliances_internet":null,"appliances_bedroom":null,"appliances_livingroom":null,"appliances_nonincluded":null,"appliances_other":null,"appliances_tv":null,"background_image":null,"background_color":null,"city_area_id":null,"contact_person_title":null,"contact_person_rating":null,"contact_person_degrees":null,"contact_person_some_url":null,"contact_person_some":null,"estate_name":null,"estate_info":null,"floor_bathroom":null,"floor_bedroom":null,"floor_kitchen":null,"floor_livingroom":null,"other_materials":null,"other_spaces":null,"postal_area_id":null,"parking_space_type":null,"parking_space_heated":null,"parking_space_electricity":null,"redemption_price":null,"shore_direction":null,"shore_length":null,"site_rent_end":null,"start_of_use_year":null,"terrace":null,"ventilation_system":null,"vrk_id":null,"vrk_apartment_id":null,"wall_bathroom":null,"wall_bedroom":null,"wall_kitchen":null,"wall_livingroom":null},"medias":[{"media_id":149738340,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738343,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738346,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738349,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738352,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738355,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738358,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738361,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738364,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738367,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1}],"building":{"building_id":86872,"building_class":1,"primary_address_id":86870,"build_year":1960,"building_type":2,"location_type":1,"floors":2,"lift":0,"sauna":1,"apartments":11,"size_min":37,"size_max":190,"status":1,"vrk_id":"1001912305"},"district":{"district_id":1680,"city_id":64,"name":"Kulosaari","status":1},"address":{"address_id":86870,"street_id":75100,"street_number":"19","building_letter":null,"zip_code_id":14731,"status":1},"city":{"city_id":64,"county_id":2,"name":"Helsinki","status":1},"street":{"street_id":75100,"city_id":64,"name":"Risto Rytin tie","status":1,"name_swe":"<NAME> v\u00e4g"},"company":{"company_id":5014209,"oikotie_company_id":40777},"oikotieCompany":{"ID":40777,"MARKETING_NAME":"Huom! | Kahdeksas p\u00e4iv\u00e4 Oy, Hitsaajankatu 24","EXTERNAL_ID":"KIVI-12339","TRADE_REGISTRY_NUMBER":"2044327-1","COMPANY_STATUS":"ACTIVE","COMPANY_TYPE":"REAL ESTATE AGENT","STREET_ADDRESS":"Hitsaajankatu 24","ZIP_CODE":"00810","CITY":"Helsinki","COUNTY":"Uusimaa","IS_FOREIGN_COMPANY":0,"EMAIL_ADDRESS":"<EMAIL>","LEAD_EMAIL_ADDRESS":null,"PHONE_NUMBER":"020 780 3950","FAX_NUMBER":null,"MAP_COORDINATE_LAT":"3384878","MAP_COORDINATE_LON":"6676668","PARENT_COMPANY_ID":91925,"PARENT_COMPANY_NAME":"Huom!","CHANGED_DATE":"2016-04-08 09:16:27","HAS_LISTLOGO":0,"HAS_CONTRACT":1,"HAS_ADGUARANTEE":1,"IS_SELF_REGISTERED":0,"IS_CREDITABLE":1,"HAS_FREESPEE":0,"SELLER_ID":7},"coordinates":{"card_id":86872,"latitude":60.186691279801,"longitude":25.017185247395},"viewings":[],"logo1":"http:\/\/asunnot.oikotie-static.edgesuite.net\/240*40\/110\/151\/logo\/110151119.jpg","logo2":"http:\/\/asunnot.oikotie-static.edgesuite.net\/240*40\/110\/151\/logo\/110151119.jpg","zipCode":{"zip_code_id":14731,"city_id":64,"zip_code":"00570","name":"Helsinki","status":1},"notifications":[]}
      END_OF_STRING

      stub_request(:get, "https://asunnot.oikotie.fi/api/cards?cardType=100&limit=12&offset=0&price%5Bmin%5D=1000000").to_return(body: canned_cards_answer, headers: { 'Content-Type' => "text/json" })
      stub_request(:get, "https://asunnot.oikotie.fi/myytavat-asunnot/13089288?format=json").to_return(body: canned_card_answer, headers: { 'Content-Type' => "text/json" })

      expect {
          get :index
        }.to change(Card, :count).by(1)

      expect(session[:referrer]).to eq('http://test.host/')
    end

    it "should on duplicate call use cache and not insert new cards" do
      canned_cards_answer = <<-END_OF_STRING
      {"cards":[{"id":13089288,"description":"Tyylik\u00e4s ja valoisa 4\/5 kerroksen kulmahuoneisto halutussa ja vehre\u00e4ss\u00e4 Vuoreksen uudessa kaupunginosassa","rooms":1,"roomConfiguration":"1h, kt, kph, parveke","price":"122\u00a0800\u00a0\u20ac","nextViewing":null,"images":{"wide":"http:\/\/asunnot.oikotie-static.edgesuite.net\/623*464\/142\/790\/wide\/142790490.jpg","thumb":"http:\/\/asunnot.oikotie-static.edgesuite.net\/215*161\/142\/790\/thumb_search\/142790490.jpg"},"newDevelopment":true,"published":"2016-04-30T12:18:09Z","size":32.5,"sizeLot":4700,"cardType":100,"contractType":1,"onlineOffer":null,"extraVisibility":null,"extraVisibilityString":null,"buildingData":{"address":"Koukkurannankatu 6 B 68","district":"Vuores","city":"Tampere","year":2016,"buildingType":1},"coordinates":{"latitude":61.43212,"longitude":23.80451},"brand":{"image":"http:\/\/asunnot.oikotie-static.edgesuite.net\/300*260\/143\/107\/company_image\/143107554.jpg","name":"Kiinteist\u00f6maailma, <NAME> Oy LKV, Tampere","id":5013593},"priceChanged":null,"visits":0,"visits_weekly":0}],"found":51321,"start":1}
      END_OF_STRING
      canned_card_answer = <<-END_OF_STRING
      {"pageName":"property","notifcationPage":4,"card_id":"13089249","ad":{"ad_apartment_sell_id":13089249,"building_id":86872,"primary_address_id":86870,"user_id":null,"apartment_condition":2,"availability_date":null,"balcony":0,"building_override_build_year":1960,"building_override_lift":0,"building_override_sauna":0,"building_rights":null,"contract_type":1,"debt_payable":null,"floor":1,"floor_count":null,"floor_location":null,"habitation_type":1,"igglo_id":"9528212","is_rented":null,"kitchen":null,"new_development":0,"new_development_status":null,"price":239000,"published":"2016-05-15 14:53:48","published_search_sort":"2016-05-15 14:53:48","first_showing":null,"room_configuration":"2 h, kk ja psh","rooms":2,"sauna":0,"sauna_charge":null,"sauna_charge_unit":null,"sell_status":3,"shore_ownership_type":null,"shore_type":null,"size":37,"size_office":null,"source_type":1,"status":1,"title":"Ainutlaatuinen rivitalokoti rauhallisella alueella","usage_fee":null},"adExtra":{"ad_apartment_sell_id":13089249,"private_vendor_ad_id":null,"address_info":"Risto Rytin tie 19","area_description_info":null,"attachments_info":null,"attachments_url":null,"antenna_system_info":"kaapeli-tv","apartment_number":null,"availability_info":"sopimuksen mukaan","balcony_info":null,"bathroom_appliance_info":"Varustus: pesukoneliit\u00e4nt\u00e4, wc, suihku, peilikaappi.","build_year_info":"1960","building_extra_info":null,"building_override_apartment_house_company":null,"building_override_apartment_sizes_total":1237,"building_override_apartments":11,"building_override_building_material_info":"puu, tiili","building_override_building_plan_info":"Kaavamuutoksia vireill\u00e4. Lis\u00e4tietoa Helsingin kaupunki.","building_override_building_plan_situation":"Asemakaava","building_override_building_subtype":null,"building_override_building_type":2,"building_override_business_premises":null,"building_override_business_premises_sizes_total":null,"building_override_core_type":null,"building_override_exterior_material_info":null,"building_override_energy_class":"F2007","building_override_energy_flag":1,"building_override_floors":1,"building_override_heating_method":null,"building_override_location_type":null,"building_override_lot_ownership":1,"building_override_lot_ownership_info":null,"building_override_lot_rent_contract_until":null,"building_override_lot_size":null,"building_override_price_max":null,"building_override_price_min":null,"building_override_renovation_balcony":null,"building_override_renovation_facade":null,"building_override_renovation_other":null,"building_override_renovation_pipe":null,"building_override_renovation_roof":null,"building_override_renovation_window":null,"building_override_renovation_yard":null,"building_override_roof_material_info":"Pelti","building_override_roof_type_info":"Tasa","building_override_rooms_max":null,"building_override_rooms_min":null,"building_override_size_max":null,"building_override_size_min":null,"building_override_superintendent":"Juha Korpi Lapinrinne 2, 00180 Helsinki Is\u00e4nn\u00f6intipalvelu Isarvo Oy P. 0400 153 789","building_override_technical_information":null,"building_override_total_size":null,"building_override_transfer_limitations":null,"building_override_usage":null,"building_override_ventilation":null,"cable_tv_charge":null,"cable_tv_charge_unit":null,"car_storage_info":null,"car_storage_unit":null,"car_storage_cost":null,"buyer_costs":null,"building_rights_unit":null,"comment":null,"condition_inspection_info":null,"common_areas_info":"v\u00e4est\u00f6nsuoja.","completion_time":null,"condition_info":"Hyv\u00e4","connections_info":null,"contact_email":"<EMAIL>","contact_email_2":null,"contact_email_3":null,"contact_address":null,"contact_name":"<NAME>","contact_person_picture_url":"http:\/\/img.cromet.fi\/itemimages\/suppliercont\/www\/209.12339\/img338089823748153121.jpg","contact_phone":"040 680 7709","contact_show":null,"contract_date":null,"description":"Ainutlaatuinen rivitalokoti rauhallisella alueella.Hyvin hoidettu taloyhti\u00f6 jossa juuri tehty ikkuna- katto- ja julkisivuremontti.Valoisa koti odottaa uutta asukasta sopii erinomaisesti vaikka ensiasunnoksi tule ja tutustu.Esittelyt <NAME>en 040 680 7709 tai <EMAIL>.Oma koti viel\u00e4 myym\u00e4tt\u00e4? Pyyd\u00e4 minut maksuttomalle arvioik\u00e4ynnille niin katsomme kotinne arvon.","description_supplementary":null,"direction_info":null,"direction_window_info":null,"driving_instructions":null,"electricity_consumption_average":null,"electricity_consumption_annual":null,"electricity_consumption_unit":null,"encumbrances_info":null,"estate_ownership_type":0,"estate_premises_and_profits":null,"estate_tax":null,"financial_fee":113.77,"financing_offer_1_fee":null,"financing_offer_1_percentage":null,"financing_offer_1_price":null,"financing_offer_2_fee":null,"financing_offer_2_percentage":null,"financing_offer_2_price":null,"floor_location":"1\/1","floor_material_info":"Lattia: Keitti\u00f6ss\u00e4: laatta. Pesutiloissa: laatta. Olohuoneessa: laminaatti. Makuuhuoneessa: laminaatti. Sein\u00e4t: Keitti\u00f6ss\u00e4: kaakeli, maalattu. Pesutiloissa: kaakeli. Olohuoneessa: tapetti. Makuuhuoneessa: tapetti. Sein\u00e4materiaalien kuvaus: Makuuhuoneen yksi sein\u00e4 \u00e4\u00e4nieristett\u00e4v\u00e4.","foundation_info":null,"grounds_info":null,"heating_cost":null,"heating_info":"kauko","hobby_possibilities":null,"honoring_clause":"ei lunastusoikeutta","housing_company_name":"<NAME>","hunting_right":null,"kitchen_appliance_info":"Liesi: s\u00e4hk\u00f6liesi. Ty\u00f6tasot: puu. Kylm\u00e4s\u00e4ilytys: j\u00e4\u00e4kaappi\/pakastin. Varustus: liesituuletin.","lease_holder":null,"lift_info":null,"link_text":null,"living_area_info":null,"living_area_type":null,"lot_fee":null,"lot_rent":null,"lot_repurchase_price":null,"inquiries":null,"maintenance_fee":170,"management_charge":283.77,"management_method_info":"Asukkaat.","mode_of_financing":null,"more_info_text":null,"mortgages_info":null,"municipal_development_info":null,"new_apartment_reserved":null,"other_appliances":null,"other_buildings_info":null,"other_fees_info":null,"other_premises":null,"ownership_type":null,"parking_fee":null,"parking_space_info":"autotalleja 5, piha-autopaikkoja 15,","partner_paper":0,"price_sell":218854.92,"publish_purchase_price":null,"real_estate_id":null,"renovation_bathroom":null,"renovation_future_info":"L\u00e4hiaikojen korjaukset: Viem\u00e4reiden kunnostus pinnoittamalla, mik\u00e4li hanketta selvitett\u00e4ess\u00e4 todetaan mahdolliseksi.","renovation_info":"Autotallien katto v.2000, Kaukol\u00e4mp\u00f6keskus v.2002, LV+KV putket v. 2004. Pihan asfaltointi v.2012. Katto- julkisivu- ja ikkunaremontti. 2014-2015","renovation_kitchen":null,"renovation_other":null,"rent_income_monthly":null,"rent_term_info":null,"rented":null,"sanitation_info":null,"road_costs":null,"sauna_fee":null,"sauna_info":null,"sell_comments":null,"sell_date":null,"sell_type":null,"sender_node":"ext022","services_info":null,"sewage_and_water_info":null,"sewer_system_info":null,"share_of_debt_70":null,"share_of_debt_85":null,"share_of_liabilities":null,"shore_direction":null,"shore_length":null,"shore_info":null,"shores_description_info":null,"show_lead_form":null,"size_floor":null,"size_total":37,"storage_info":null,"use_of_water":null,"vista_info":null,"virtual_presentation_text":null,"virtual_presentation_url":null,"water_fee":22,"water_fee_info":"22 EUR\/hl\u00f6\/kk","waters":null,"waters_info":null,"yard_direction":null,"yard_info":null,"district_info":"Kulosaari","city_info":"Helsinki","zip_code_info":"00570"},"additionalInfo":{"card_id":13089249,"apartment_city_plan_id":null,"appliances_internet":null,"appliances_bedroom":null,"appliances_livingroom":null,"appliances_nonincluded":null,"appliances_other":null,"appliances_tv":null,"background_image":null,"background_color":null,"city_area_id":null,"contact_person_title":null,"contact_person_rating":null,"contact_person_degrees":null,"contact_person_some_url":null,"contact_person_some":null,"estate_name":null,"estate_info":null,"floor_bathroom":null,"floor_bedroom":null,"floor_kitchen":null,"floor_livingroom":null,"other_materials":null,"other_spaces":null,"postal_area_id":null,"parking_space_type":null,"parking_space_heated":null,"parking_space_electricity":null,"redemption_price":null,"shore_direction":null,"shore_length":null,"site_rent_end":null,"start_of_use_year":null,"terrace":null,"ventilation_system":null,"vrk_id":null,"vrk_apartment_id":null,"wall_bathroom":null,"wall_bedroom":null,"wall_kitchen":null,"wall_livingroom":null},"medias":[{"media_id":149738340,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738343,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738346,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738349,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738352,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738355,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738358,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738361,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738364,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1},{"media_id":149738367,"user_id":63236,"name":null,"mimetype":"image\/jpeg","processor_type":1,"status":1}],"building":{"building_id":86872,"building_class":1,"primary_address_id":86870,"build_year":1960,"building_type":2,"location_type":1,"floors":2,"lift":0,"sauna":1,"apartments":11,"size_min":37,"size_max":190,"status":1,"vrk_id":"1001912305"},"district":{"district_id":1680,"city_id":64,"name":"Kulosaari","status":1},"address":{"address_id":86870,"street_id":75100,"street_number":"19","building_letter":null,"zip_code_id":14731,"status":1},"city":{"city_id":64,"county_id":2,"name":"Helsinki","status":1},"street":{"street_id":75100,"city_id":64,"name":"<NAME>in tie","status":1,"name_swe":"<NAME> v\u00e4g"},"company":{"company_id":5014209,"oikotie_company_id":40777},"oikotieCompany":{"ID":40777,"MARKETING_NAME":"Huom! | Kahdeksas p\u00e4iv\u00e4 Oy, Hitsaajankatu 24","EXTERNAL_ID":"KIVI-12339","TRADE_REGISTRY_NUMBER":"2044327-1","COMPANY_STATUS":"ACTIVE","COMPANY_TYPE":"REAL ESTATE AGENT","STREET_ADDRESS":"Hitsaajankatu 24","ZIP_CODE":"00810","CITY":"Helsinki","COUNTY":"Uusimaa","IS_FOREIGN_COMPANY":0,"EMAIL_ADDRESS":"<EMAIL>","LEAD_EMAIL_ADDRESS":null,"PHONE_NUMBER":"020 780 3950","FAX_NUMBER":null,"MAP_COORDINATE_LAT":"3384878","MAP_COORDINATE_LON":"6676668","PARENT_COMPANY_ID":91925,"PARENT_COMPANY_NAME":"Huom!","CHANGED_DATE":"2016-04-08 09:16:27","HAS_LISTLOGO":0,"HAS_CONTRACT":1,"HAS_ADGUARANTEE":1,"IS_SELF_REGISTERED":0,"IS_CREDITABLE":1,"HAS_FREESPEE":0,"SELLER_ID":7},"coordinates":{"card_id":86872,"latitude":60.186691279801,"longitude":25.017185247395},"viewings":[],"logo1":"http:\/\/asunnot.oikotie-static.edgesuite.net\/240*40\/110\/151\/logo\/110151119.jpg","logo2":"http:\/\/asunnot.oikotie-static.edgesuite.net\/240*40\/110\/151\/logo\/110151119.jpg","zipCode":{"zip_code_id":14731,"city_id":64,"zip_code":"00570","name":"Helsinki","status":1},"notifications":[]}
      END_OF_STRING

      stub_request(:get, "https://asunnot.oikotie.fi/api/cards?cardType=100&limit=12&offset=0&price%5Bmin%5D=1000000").to_return(body: canned_cards_answer, headers: { 'Content-Type' => "text/json" })
      stub_request(:get, "https://asunnot.oikotie.fi/myytavat-asunnot/13089288?format=json").to_return(body: canned_card_answer, headers: { 'Content-Type' => "text/json" })

      expect {
          get :index
        }.to change(Card, :count).by(1)

      expect {
          get :index
        }.to change(Card, :count).by(0)
    end
  end

  describe "#show" do
    context "card without relations" do
      it "assigns the requested card as @card" do
        get :show, {:id => card.to_param}
        expect(assigns(:card)).to eq(card)
      end
    end

    context "card with feature relations" do
      let!(:feature) { FactoryGirl.create :feature, card: card }

      it "assigns the requested card as @card" do
        get :show, {:id => card.to_param}
        expect(assigns(:card)).to eq(card)
      end
    end

    it "should use session referrer if set" do
      session[:referrer] = 'http://test.host?limit=100'
      get :show, {:id => card.to_param}
    end
  end
end

{'fraction_non_alphanumeric': 0.18108421931129576, 'fraction_numerical': 0.07278928843571973, 'mean_word_length': 17.915236787920385, 'pattern_counts': {'":': 1784, '<': 55, '<?xml version=': 0, '>': 55, 'https://': 8, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '120285', 'n_tokens_mistral': 22606, 'n_tokens_neox': 19706, 'n_words': 1041}