Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 148 lines (116 sloc) 5.034 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
require "spec_helper"

module Refinery
  module Inquiries
    module Admin
      describe Inquiry do
        refinery_login_with :refinery_user

        let!(:inquiry) do
          Factory(:inquiry, :name => "David Jones",
                            :email => "dave@refinerycms.com",
                            :message => "Hello, I really like your website. Was it hard to build and maintain or could anyone do it?")
        end

        context "when no" do
          before(:each) { Refinery::Inquiries::Inquiry.destroy_all }

          context "inquiries" do
            it "shows message" do
              visit refinery.inquiries_admin_inquiries_path

              page.should have_content("You have not received any inquiries yet.")
            end
          end

          context "spam inquiries" do
            it "shows message" do
              visit refinery.spam_inquiries_admin_inquiries_path

              page.should have_content("Hooray! You don't have any spam.")
            end
          end
        end

        describe "action links" do
          before(:each) { visit refinery.inquiries_admin_inquiries_path }

          specify "in the side pane" do
            within "#actions" do
              page.should have_content("Inbox")
              page.should have_selector("a[href='/refinery/inquiries']")
              page.should have_content("Spam")
              page.should have_selector("a[href='/refinery/inquiries/spam']")
              page.should have_content("Update who gets notified")
              page.should have_selector("a[href*='/refinery/inquiries/settings/inquiry_notification_recipients/edit']")
              page.should have_content("Edit confirmation email")
              page.should have_selector("a[href*='/refinery/inquiries/settings/inquiry_confirmation_body/edit']")
            end
          end
        end

        describe "index" do
          it "shows inquiry list" do
            visit refinery.inquiries_admin_inquiries_path

            page.should have_content("David Jones said Hello, I really like your website. Was it hard to build ...")
          end
        end

        describe "show" do
          it "shows inquiry details" do
            visit refinery.inquiries_admin_inquiries_path

            click_link "Read the inquiry"

            page.should have_content("From David Jones [dave@refinerycms.com]")
            page.should have_content("Hello, I really like your website. Was it hard to build and maintain or could anyone do it?")
            within "#actions" do
              page.should have_content("Age")
              page.should have_content("Back to all Inquiries")
              page.should have_selector("a[href='/refinery/inquiries']")
              page.should have_content("Remove this inquiry forever")
              page.should have_selector("a[href='/refinery/inquiries/#{inquiry.id}']")
            end
          end
        end

        describe "destroy" do
          it "removes inquiry" do
            visit refinery.inquiries_admin_inquiries_path

            click_link "Remove this inquiry forever"

            page.should have_content("'#{inquiry.name}' was successfully removed.")
            Refinery::Inquiries::Inquiry.count.should == 0
          end
        end

        describe "spam" do
          it "moves inquiry to spam" do
            visit refinery.inquiries_admin_inquiries_path

            click_link "Mark as spam"

            within "#actions" do
              page.should have_content("Spam (1)")
              click_link "Spam (1)"
            end

            page.should have_content("David Jones said Hello, I really like your website. Was it hard to build ...")
          end
        end

        describe "update who gets notified" do
          before do
            Rails.cache.clear
            Refinery::Inquiries::Setting.notification_recipients
          end

          it "sets receiver", :js => true do
            visit refinery.inquiries_admin_inquiries_path

            click_link "Update who gets notified"

            within_frame "dialog_iframe" do
              fill_in "setting_value", :with => "phil@refinerycms.com"
              click_button "submit_button"
            end

            page.should have_content("Notification Recipients was successfully updated.")
          end
        end

        describe "updating confirmation email copy" do
          before do
            Rails.cache.clear
            Refinery::Inquiries::Setting.confirmation_body
          end

          it "sets message", :js => true do
            visit refinery.inquiries_admin_inquiries_path

            click_link "Edit confirmation email"

            within_frame "dialog_iframe" do
              fill_in "subject__en", :with => "subject"
              fill_in "message__en", :with => "message"
              click_button "Save"
            end

            page.should have_content("Confirmation Body was successfully updated.")
          end
        end

      end
    end
  end
end
Something went wrong with that request. Please try again.