refinerycms-inquiries 1.0.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. data/.gitignore +3 -0
  2. data/.travis.yml +16 -0
  3. data/Gemfile +68 -0
  4. data/Guardfile +20 -0
  5. data/Rakefile +19 -0
  6. data/app/assets/stylesheets/refinery/inquiries/inquiries.css.scss +21 -0
  7. data/app/controllers/refinery/inquiries/admin/inquiries_controller.rb +50 -0
  8. data/app/controllers/refinery/inquiries/admin/settings_controller.rb +56 -0
  9. data/app/controllers/refinery/inquiries/inquiries_controller.rb +47 -0
  10. data/app/helpers/refinery/inquiries/inquiries_helper.rb +6 -0
  11. data/app/mailers/refinery/inquiries/inquiry_mailer.rb +22 -0
  12. data/app/models/refinery/inquiries/inquiry.rb +27 -0
  13. data/app/models/refinery/inquiries/setting.rb +63 -0
  14. data/app/views/refinery/inquiries/admin/inquiries/_inquiry.html.erb +27 -0
  15. data/app/views/refinery/inquiries/admin/inquiries/_submenu.html.erb +27 -0
  16. data/app/views/{admin → refinery/inquiries/admin}/inquiries/index.html.erb +2 -2
  17. data/app/views/{admin → refinery/inquiries/admin}/inquiries/show.html.erb +9 -7
  18. data/app/views/refinery/inquiries/admin/settings/_confirmation_email_form.html.erb +59 -0
  19. data/app/views/{admin/inquiry_settings → refinery/inquiries/admin/settings}/_notification_recipients_form.html.erb +3 -3
  20. data/app/views/{admin/inquiry_settings → refinery/inquiries/admin/settings}/edit.html.erb +1 -1
  21. data/app/views/refinery/inquiries/inquiries/new.html.erb +32 -0
  22. data/app/views/refinery/inquiries/inquiries/thank_you.html.erb +1 -0
  23. data/app/views/refinery/inquiries/inquiry_mailer/confirmation.text.erb +1 -0
  24. data/app/views/refinery/inquiries/inquiry_mailer/notification.text.erb +18 -0
  25. data/config/locales/bg.yml +77 -0
  26. data/config/locales/cs.yml +68 -66
  27. data/config/locales/da.yml +60 -58
  28. data/config/locales/de.yml +69 -67
  29. data/config/locales/en-GB.yml +68 -66
  30. data/config/locales/en.yml +68 -66
  31. data/config/locales/es.yml +71 -69
  32. data/config/locales/fr.yml +69 -67
  33. data/config/locales/it.yml +70 -68
  34. data/config/locales/lolcat.yml +69 -67
  35. data/config/locales/lt.yml +69 -67
  36. data/config/locales/lv.yml +69 -67
  37. data/config/locales/nb.yml +70 -68
  38. data/config/locales/nl.yml +69 -67
  39. data/config/locales/pl.yml +69 -67
  40. data/config/locales/pt-BR.yml +69 -67
  41. data/config/locales/ru.yml +69 -67
  42. data/config/locales/sk.yml +69 -67
  43. data/config/locales/sl.yml +69 -67
  44. data/config/locales/sv.yml +69 -67
  45. data/config/locales/zh-CN.yml +69 -67
  46. data/config/routes.rb +16 -16
  47. data/db/migrate/20101208082840_create_inquiries.rb +16 -34
  48. data/db/seeds.rb +50 -0
  49. data/lib/generators/refinery/inquiries/inquiries_generator.rb +19 -0
  50. data/lib/refinery/inquiries/configuration.rb +9 -0
  51. data/lib/refinery/inquiries/engine.rb +28 -0
  52. data/lib/refinery/inquiries.rb +26 -0
  53. data/lib/refinerycms-inquiries.rb +1 -23
  54. data/readme.md +12 -4
  55. data/refinerycms-inquiries.gemspec +11 -86
  56. data/spec/factories/inquiry.rb +7 -0
  57. data/spec/models/refinery/inquiries/inquiry_spec.rb +52 -0
  58. data/spec/requests/refinery/inquiries/admin/inquiries_spec.rb +138 -0
  59. data/spec/requests/refinery/inquiries/inquiries_spec.rb +81 -0
  60. data/spec/spec_helper.rb +56 -0
  61. data/tasks/rspec.rake +4 -0
  62. metadata +114 -39
  63. data/app/controllers/admin/inquiries_controller.rb +0 -41
  64. data/app/controllers/admin/inquiry_settings_controller.rb +0 -43
  65. data/app/controllers/inquiries_controller.rb +0 -43
  66. data/app/helpers/inquiries_helper.rb +0 -2
  67. data/app/mailers/inquiry_mailer.rb +0 -20
  68. data/app/models/inquiry.rb +0 -21
  69. data/app/models/inquiry_setting.rb +0 -33
  70. data/app/views/admin/inquiries/_inquiry.html.erb +0 -24
  71. data/app/views/admin/inquiries/_submenu.html.erb +0 -27
  72. data/app/views/admin/inquiry_settings/_confirmation_email_form.html.erb +0 -57
  73. data/app/views/inquiries/new.html.erb +0 -34
  74. data/app/views/inquiries/thank_you.html.erb +0 -1
  75. data/app/views/inquiry_mailer/confirmation.html.erb +0 -1
  76. data/app/views/inquiry_mailer/notification.html.erb +0 -18
  77. data/db/migrate/20101208082841_remove_position_and_open_from_inquiries.rb +0 -11
  78. data/db/seeds/pages_for_inquiries.rb +0 -55
  79. data/features/create_inquiries.feature +0 -38
  80. data/features/manage_inquiries.feature +0 -57
  81. data/features/step_definitions/inquiry_steps.rb +0 -25
  82. data/features/support/factories.rb +0 -7
  83. data/features/support/paths.rb +0 -26
  84. data/lib/gemspec.rb +0 -29
  85. data/lib/generators/refinerycms_inquiries_generator.rb +0 -6
  86. data/lib/inquiries.rb +0 -2
  87. data/spec/models/inquiry_spec.rb +0 -59
@@ -1,33 +0,0 @@
1
- class InquirySetting < ActiveRecord::Base
2
-
3
- def self.confirmation_body
4
- RefinerySetting.find_or_set(:inquiry_confirmation_body,
5
- "Thank you for your inquiry %name%,\n\nThis email is a receipt to confirm we have received your inquiry and we'll be in touch shortly.\n\nThanks."
6
- )
7
- end
8
-
9
- def self.confirmation_subject
10
- RefinerySetting.find_or_set(:inquiry_confirmation_subject,
11
- "Thank you for your inquiry")
12
- end
13
-
14
- def self.confirmation_subject=(value)
15
- # handles a change in Refinery API
16
- if RefinerySetting.methods.map(&:to_sym).include?(:set)
17
- RefinerySetting.set(:inquiry_confirmation_subject, value)
18
- else
19
- RefinerySetting[:inquiry_confirmation_subject] = value
20
- end
21
- end
22
-
23
- def self.notification_recipients
24
- RefinerySetting.find_or_set(:inquiry_notification_recipients,
25
- ((Role[:refinery].users.first.email rescue nil) if defined?(Role)).to_s)
26
- end
27
-
28
- def self.notification_subject
29
- RefinerySetting.find_or_set(:inquiry_notification_subject,
30
- "New inquiry from your website")
31
- end
32
-
33
- end
@@ -1,24 +0,0 @@
1
- <li class='clearfix record <%= cycle("on", "on-hover") %>'>
2
- <span class='title'>
3
- <%= link_to inquiry.name, admin_inquiry_url(inquiry) %> <%= t('.said') %>
4
- <span class="preview"><%= truncate(strip_tags(inquiry.message), :length => 60) -%></span>
5
- </span>
6
- <span class='actions'>
7
- <%= link_to refinery_icon_tag('delete.png'), admin_inquiry_url(inquiry),
8
- { :method => :delete,
9
- :confirm => t('shared.admin.delete.message', :title => inquiry.name) },
10
- :class => "cancel confirm-delete",
11
- :title => t('admin.inquiries.delete') -%>
12
-
13
- <%= link_to refinery_icon_tag('zoom.png'), admin_inquiry_url(inquiry),
14
- :title => t('.read_inquiry') -%>
15
-
16
- <% if inquiry.spam? %>
17
- <%= link_to refinery_icon_tag('email.png'), toggle_spam_admin_inquiry_url(inquiry),
18
- :title => t('.mark_as_ham') -%>
19
- <% else %>
20
- <%= link_to refinery_icon_tag('bin_closed.png'), toggle_spam_admin_inquiry_url(inquiry),
21
- :title => t('.mark_as_spam') -%>
22
- <% end %>
23
- </span>
24
- </li>
@@ -1,27 +0,0 @@
1
- <div id='actions'>
2
- <ul>
3
- <li>
4
- <%= render :partial => "/shared/admin/search", :locals => {:url => request.path} %>
5
- </li>
6
- <li <%= "class='selected'" if params[:action] == "index" %>>
7
- <%= link_to t('.inbox'), admin_inquiries_url, :class => "email_icon" %>
8
- </li>
9
- <li <%= "class='selected'" if params[:action] == "spam" %>>
10
- <% if @spam_count > 0 %>
11
- <%= link_to "#{t('.spam')} (#{@spam_count})", spam_admin_inquiries_url, :class => "spam_icon" %>
12
- <% else %>
13
- <%= link_to t('.spam'), spam_admin_inquiries_url, :class => "spam_empty_icon" %>
14
- <% end %>
15
- </li>
16
- <li>
17
- <%= link_to t('.update_notified'),
18
- edit_admin_inquiry_setting_url(:inquiry_notification_recipients, :dialog => true, :height => 300),
19
- :class => "user_comment_icon" %>
20
- </li>
21
- <li>
22
- <%= link_to t('.edit_confirmation_email'),
23
- edit_admin_inquiry_setting_url(:inquiry_confirmation_body, :dialog => true),
24
- :class => "edit_email_icon" %>
25
- </li>
26
- </ul>
27
- </div>
@@ -1,57 +0,0 @@
1
- <%= form_for([:admin, @refinery_setting], :url => (@url_override || @url)) do |f| %>
2
-
3
- <p>
4
- <%= t('.explanation') %>
5
- </p>
6
- <p>
7
- <%= t('.below_edit_email_sent') %>
8
- </p>
9
- <table id='inquiry'>
10
- <tr>
11
- <td>
12
- <label class='stripped'><%= t('.to') %></label>
13
- </td>
14
- <td>
15
- <%= t('.the_customer_making_inquiry') %>
16
- </td>
17
- </tr>
18
- <tr>
19
- <td>
20
- <label class='stripped'><%= t('.from') %></label>
21
- </td>
22
- <td>
23
- <%= "#{RefinerySetting[:site_name]} &lt;no-reply@#{request.domain(RefinerySetting.find_or_set(:tld_length, 1))}&gt;".html_safe %>
24
- </td>
25
- </tr>
26
- <tr>
27
- <td>
28
- <label class='stripped'><%= t('.subject') %></label>
29
- </td>
30
- <td>
31
- <%= text_field_tag 'subject', InquirySetting.confirmation_subject,
32
- :class => 'widest' %>
33
- </td>
34
- </tr>
35
- <tr>
36
- <td valign='top'>
37
- <%= f.label :value, t('.message'),
38
- :class => 'stripped' %>
39
- </td>
40
- <td>
41
- <%= f.text_area :value, :value => f.object.value, # required, we can't use :value
42
- :rows => "5",
43
- :class => 'widest' %>
44
- <br/>
45
- <em><%= t('.note') %></em>
46
- </td>
47
- </tr>
48
- </table>
49
-
50
- <%= render :partial => "/shared/admin/form_actions",
51
- :locals => {
52
- :f => f,
53
- :continue_editing => false,
54
- :cancel_url => admin_inquiries_url,
55
- :hide_delete => true
56
- } %>
57
- <% end %>
@@ -1,34 +0,0 @@
1
- <% content_for :body_content_left do %>
2
- <div class='inquiries'>
3
- <%=raw @page[Page.default_parts.first.to_sym] %>
4
-
5
- <%= form_for @inquiry do |f| %>
6
- <%= render :partial => "/shared/admin/error_messages",
7
- :locals => {
8
- :object => @inquiry,
9
- :include_object_name => true
10
- } %>
11
- <div class='field'>
12
- <%= f.required_label :name %>
13
- <%= f.text_field :name %>
14
- </div>
15
- <div class='field'>
16
- <%= f.required_label :email %>
17
- <%= f.text_field :email %>
18
- </div>
19
- <div class='field'>
20
- <%= f.label :phone %>
21
- <%= f.text_field :phone %>
22
- </div>
23
- <div class='field message_field'>
24
- <%= f.required_label :message %>
25
- <%= f.text_area :message, :rows => 8 %>
26
- </div>
27
- <div class='actions'>
28
- <%= f.submit t('.send') %>
29
- <%= link_to t('.privacy_policy'), "/pages/privacy-policy", :id => "privacy_link" if RefinerySetting.find_or_set(:show_contact_privacy_link, false) %>
30
- </div>
31
- <% end %>
32
- </div>
33
- <% end %>
34
- <%= render :partial => "/shared/content_page" %>
@@ -1 +0,0 @@
1
- <%= render :partial => "/shared/content_page" %>
@@ -1 +0,0 @@
1
- <%= InquirySetting.confirmation_body.gsub("%name%", @inquiry.name) %>
@@ -1,18 +0,0 @@
1
- <%= t('.greeting') %>,
2
-
3
- <%= t('.you_recieved_new_inquiry') %>
4
-
5
- <%= t('.inquiry_starts') %>
6
-
7
- <%= t('.from') %>: <%= @inquiry.name %>
8
- <%= t('.email') %>: <%= @inquiry.email %>
9
- <%= t('.phone') %>: <%= @inquiry.phone %>
10
- <%= t('.message') %>:
11
- <%= @inquiry.message %>
12
-
13
- <%= t('.inquiry_ends') %>
14
-
15
- <%= t('.closing_line') %>,
16
- <%= RefinerySetting[:site_name] %>
17
-
18
- <%= t('.ps') %>
@@ -1,11 +0,0 @@
1
- class RemovePositionAndOpenFromInquiries < ActiveRecord::Migration
2
- def self.up
3
- remove_column :inquiries, :position
4
- remove_column :inquiries, :open
5
- end
6
-
7
- def self.down
8
- add_column :inquiries, :position, :integer
9
- add_column :inquiries, :open, :boolean, :default => true
10
- end
11
- end
@@ -1,55 +0,0 @@
1
- ::User.find(:all).each do |user|
2
- if user.plugins.where(:name => 'refinery_inquiries').blank?
3
- user.plugins.create(:name => "refinery_inquiries",
4
- :position => (user.plugins.maximum(:position) || -1) +1)
5
- end
6
- end if defined?(::User)
7
-
8
- if defined?(::Page)
9
- page_position = (::Page.maximum(:position, :conditions => {:parent_id => nil}) || -1)
10
-
11
- contact_us_page = ::Page.create({
12
- :title => "Contact",
13
- :link_url => "/contact",
14
- :menu_match => "^/(inquiries|contact).*$",
15
- :deletable => false,
16
- :position => (page_position += 1)
17
- })
18
- contact_us_page.parts.create({
19
- :title => "Body",
20
- :body => "<p>Get in touch with us. Just use the form below and we'll get back to you as soon as we can.</p>",
21
- :position => 0
22
- })
23
- contact_us_page.parts.create({
24
- :title => "Side Body",
25
- :body => "<p>163 Evergreen Terrace<br/>Happyville<br/>USA.<br/>Phone: 1-800 CALLUSNOW</p>",
26
- :position => 1
27
- })
28
- contact_us_page_position = -1
29
-
30
- thank_you_page = contact_us_page.children.create({
31
- :title => "Thank You",
32
- :link_url => "/contact/thank_you",
33
- :menu_match => "^/(inquiries|contact)/thank_you$",
34
- :show_in_menu => false,
35
- :deletable => false,
36
- :position => (contact_us_page_position += 1)
37
- })
38
- thank_you_page.parts.create({
39
- :title => "Body",
40
- :body => "<p>We've received your inquiry and will get back to you with a response shortly.</p><p><a href='/'>Return to the home page</a></p>",
41
- :position => 0
42
- })
43
-
44
- privacy_policy_page = contact_us_page.children.create({
45
- :title => "Privacy Policy",
46
- :deletable => true,
47
- :show_in_menu => false,
48
- :position => (contact_us_page_position += 1)
49
- })
50
- privacy_policy_page.parts.create({
51
- :title => "Body",
52
- :body => "<p>We respect your privacy. We do not market, rent or sell our email list to any outside parties.</p><p>We need your e-mail address so that we can ensure that the people using our forms are bona fide. It also allows us to send you e-mail newsletters and other communications, if you opt-in. Your postal address is required in order to send you information and pricing, if you request it.</p><p>Please call us at 123 456 7890 if you have any questions or concerns.</p>",
53
- :position => 0
54
- })
55
- end
@@ -1,38 +0,0 @@
1
- @refinerycms @inquiries @inquiries-create
2
- Feature: Create Inquiries
3
- In order to contact the website owner
4
- I want to create an inquiry
5
-
6
- Background:
7
- Given A Refinery user exists
8
- And I have no inquiries
9
- And I have a page titled "Contact Us" with a custom url "/contact"
10
- And I have a page titled "Thank You" with a custom url "/contact/thank_you"
11
-
12
- Scenario: Contact page
13
- When I go to the contact page
14
- Then I should see "Name *"
15
- And I should see "Email *"
16
- And I should see "Phone"
17
- And I should see "Message *"
18
-
19
- Scenario: Create a valid inquiry
20
- When I go to the contact page
21
- And I fill in "Name *" with "Philip"
22
- And I fill in "Email *" with "phil@refinerycms.com"
23
- And I fill in "Message *" with "It sure is good to have a functional test coverage."
24
- And I press "Send"
25
- Then I should be on the contact thank you page
26
- And I should see "Thank You"
27
- And I should have 1 inquiries
28
-
29
- Scenario: Create an invalid inquiry
30
- When I go to the contact page
31
- And I press "Send"
32
- Then I should be on the contact create page
33
- And I should see "Name can't be blank"
34
- And I should not see "Email can't be blank"
35
- And I should see "Email is invalid"
36
- And I should not see "Phone can't be blank"
37
- And I should see "Message can't be blank"
38
- And I should have 0 inquiries
@@ -1,57 +0,0 @@
1
- @refinerycms @inquiries @inquiries-manage
2
- Feature: Manage Inquiries
3
- In order to see inquiries left for me on my website
4
- As an Administrator
5
- I want to manage inquiries
6
-
7
- Background:
8
- Given I am a logged in refinery user
9
- And I have no inquiries
10
- And I have an inquiry from "David Jones" with email "dave@refinerycms.com" and message "Hello, I really like your website. Was it hard to build and maintain or could anyone do it?"
11
-
12
- Scenario: Inquiries List
13
- When I go to the list of inquiries
14
- Then I should see "David Jones said Hello, I really like your website. Was it hard to build ..."
15
- And I should have 1 inquiries
16
- And I should not see "Add"
17
-
18
- Scenario: Spam List
19
- When I go to the list of inquiries
20
- And I follow "Spam"
21
- Then I should see "Hooray! You don't have any spam."
22
-
23
- @inquiry-settings
24
- Scenario: Updating who gets notified
25
- When I go to the list of inquiries
26
- And I follow "Update who gets notified"
27
- And I fill in "Send notifications to" with "phil@refinerycms.com"
28
- And I press "Save"
29
- Then I should be redirected back to "the list of inquiries"
30
- And I should see "'Notification Recipients' was successfully updated."
31
- And I should be on the list of inquiries
32
-
33
- @inquiry-settings
34
- Scenario: Updating confirmation email copy
35
- When I go to the list of inquiries
36
- And I follow "Edit confirmation email"
37
- And I fill in "Message" with "Thanks %name%! We'll never get back to you!"
38
- And I press "Save"
39
- Then I should be redirected back to "the list of inquiries"
40
- And I should see "'Confirmation Body' was successfully updated."
41
- And I should be on the list of inquiries
42
-
43
- Scenario: Inquiries Show
44
- When I go to the list of inquiries
45
- And I follow "Read the inquiry"
46
- Then I should see "From David Jones [dave@refinerycms.com]"
47
- And I should see "Hello, I really like your website. Was it hard to build and maintain or could anyone do it?"
48
- And I should see "Age"
49
- And I should see "Back to all Inquiries"
50
- And I should see "Remove this inquiry forever"
51
-
52
- Scenario: Inquiries Delete
53
- When I go to the list of inquiries
54
- And I follow "Read the inquiry"
55
- And I follow "Remove this inquiry forever"
56
- Then I should see "'David Jones' was successfully removed."
57
- And I should have 0 inquiries
@@ -1,25 +0,0 @@
1
- Given /^I have no inquiries$/ do
2
- Inquiry.delete_all
3
- end
4
-
5
- Then /^I should have ([0-9]+) inquiries?$/ do |count|
6
- Inquiry.count.should == count.to_i
7
- end
8
-
9
- Given /^I have an? inquiry from "([^"]*)" with email "([^\"]*)" and message "([^\"]*)"$/ do |name, email, message|
10
- Inquiry.create(:name => name,
11
- :email => email,
12
- :message => message)
13
- end
14
-
15
- Given /^I have an? inquiry titled "([^"]*)"$/ do |title|
16
- Inquiry.create(:name => title,
17
- :email => 'test@cukes.com',
18
- :message => 'cuking ...',
19
- :spam => false)
20
-
21
- Inquiry.create(:name => title,
22
- :email => 'test@cukes.com',
23
- :message => 'cuking ...',
24
- :spam => true)
25
- end
@@ -1,7 +0,0 @@
1
- require 'factory_girl'
2
-
3
- Factory.define :inquiry do |i|
4
- i.name "Refinery"
5
- i.email "refinery@cms.com"
6
- i.message "Hello..."
7
- end
@@ -1,26 +0,0 @@
1
- module NavigationHelpers
2
- module Refinery
3
- module Inquiries
4
- def path_to(page_name)
5
- case page_name
6
- when /the contact page/
7
- new_inquiry_path
8
-
9
- when /the contact thank you page/
10
- thank_you_inquiries_path
11
-
12
- when /the contact create page/
13
- inquiries_path
14
-
15
- when /the list of inquiries/
16
- admin_inquiries_path
17
-
18
- when /the list of spam inquiries/
19
- spam_admin_inquiries_path
20
- else
21
- nil
22
- end
23
- end
24
- end
25
- end
26
- end
data/lib/gemspec.rb DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- version = '1.0.1'
3
- raise "Could not get version so gemspec can not be built" if version.nil?
4
- files = Dir.glob("**/*").flatten.reject do |file|
5
- file =~ /\.gem$/
6
- end
7
-
8
- gemspec = <<EOF
9
- Gem::Specification.new do |s|
10
- s.name = %q{refinerycms-inquiries}
11
- s.version = %q{#{version}}
12
- s.date = %q{#{Time.now.strftime('%Y-%m-%d')}}
13
- s.summary = %q{Inquiry handling functionality for the Refinery CMS project.}
14
- s.description = %q{Inquiry handling functionality extracted from Refinery CMS to allow you to have a contact form and manage inquiries in the Refinery backend.}
15
- s.homepage = %q{http://refinerycms.com}
16
- s.email = %q{info@refinerycms.com}
17
- s.authors = ["Resolve Digital"]
18
- s.require_paths = %w(lib)
19
-
20
- s.files = [
21
- '#{files.join("',\n '")}'
22
- ]
23
- s.require_path = 'lib'
24
-
25
- s.add_dependency('filters_spam', '~> 0.2')
26
- end
27
- EOF
28
-
29
- File.open(File.expand_path("../../refinerycms-inquiries.gemspec", __FILE__), 'w').puts(gemspec)
@@ -1,6 +0,0 @@
1
- class RefinerycmsInquiries < Refinery::Generators::EngineInstaller
2
-
3
- source_root File.expand_path('../../../', __FILE__)
4
- engine_name "refinery_inquiries"
5
-
6
- end
data/lib/inquiries.rb DELETED
@@ -1,2 +0,0 @@
1
- require 'refinery'
2
- require 'filters_spam'
@@ -1,59 +0,0 @@
1
- require 'spec_helper'
2
-
3
- Dir[File.expand_path('../../../features/support/factories.rb', __FILE__)].each {|f| require f}
4
-
5
- describe Inquiry do
6
- describe "validations" do
7
- before(:each) do
8
- @attr = {
9
- :name => "rspec",
10
- :email => "rspec@refinery.com",
11
- :message => "test"
12
- }
13
- end
14
-
15
- it "rejects empty name" do
16
- Inquiry.new(@attr.merge(:name => "")).should_not be_valid
17
- end
18
-
19
- it "rejects empty message" do
20
- Inquiry.new(@attr.merge(:message => "")).should_not be_valid
21
- end
22
-
23
- it "rejects invalid email format" do
24
- ["", "@refinerycms.com", "refinery@cms", "refinery@cms.123"].each do |email|
25
- Inquiry.new(@attr.merge(:email => email)).should_not be_valid
26
- end
27
- end
28
- end
29
-
30
- describe "default scope" do
31
- it "orders by created_at in desc" do
32
- inquiry1 = Factory(:inquiry, :created_at => 1.hour.ago)
33
- inquiry2 = Factory(:inquiry, :created_at => 2.hours.ago)
34
- inquiries = Inquiry.all
35
- inquiries.first.should == inquiry1
36
- inquiries.second.should == inquiry2
37
- end
38
- end
39
-
40
- describe ".latest" do
41
- it "returns latest 7 non-spam inquiries by default" do
42
- 8.times { Factory(:inquiry) }
43
- Inquiry.last.toggle!(:spam)
44
- Inquiry.latest.length.should == 7
45
- end
46
-
47
- it "returns latest 7 inquiries including spam ones" do
48
- 4.times { Factory(:inquiry) }
49
- 3.times { Factory(:inquiry) }
50
- Inquiry.all[0..2].each { |inquiry| inquiry.toggle!(:spam) }
51
- Inquiry.latest(7, true).length.should == 7
52
- end
53
-
54
- it "returns latest n inquiries" do
55
- 4.times { Factory(:inquiry) }
56
- Inquiry.latest(3).length.should == 3
57
- end
58
- end
59
- end