Sha256: 3ba536ffcf1ebebe10e4c925f6348f8988a38e6611b4930b45c3d26fd825d7c3

Contents?: true

Size: 1.92 KB

Versions: 2

Compression:

Stored size: 1.92 KB

Contents

require 'spec_helper'
require 'json'

describe GlobalizeTranslationsController do

  render_views
  let(:page) { Capybara::Node::Simple.new(@response.body) }
  let(:i18n_title) { Factory(:i18n_title) }

  context "JSON" do

    describe "GET :show" do
      let(:translations) do
        i18n_title # needed so there is some data in the database before a call to get :show
        get :show, :format => :json
        JSON.parse(response.body)
      end

      it "returns a non-empty JSON" do
        translations.present?.should be_true
      end

      it "returns a JSON with default_locale" do
        translations["default_locale"].should eq(I18n.default_locale.to_s)
      end

      it "returns a JSON with translations" do
        i18n_title.value.should eq(translations["en"]["title"])
      end
    end

  end

  context "HTML" do

    describe "GET :show" do
      context "without being logged in" do
        before do
          get :show
        end

        it { should respond_with(:forbidden) }
      end

      context "when being logged in as admin" do
        before do
          controller.stub!(:require_admin).and_return(true)
          get :show
        end

        it { should respond_with(:success) }

        it "displays Globalize request host" do
          page.should have_selector('p.request_host')
        end
      end
    end

    describe "PUT :update" do
      let(:intro) { "Introduction" }
      let(:translations) { { :en => { :intro => intro } } }

      before do
        controller.stub!(:require_admin).and_return(true)
        GlobalizeApp.any_instance.stub(:fetch_translations) { translations }
        put :update
      end

      it "updates the translations" do
        I18n.t(:intro).should eq(intro)
      end

      it "sets a flash notice" do
        flash[:notice].should_not be_empty
      end

      it "displays a flash notice" do
        page.should have_selector('p.notice')
      end
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
exvo_globalize-0.2.1 spec/controllers/globalize_translations_controller_spec.rb
exvo_globalize-0.2.0 spec/controllers/globalize_translations_controller_spec.rb