simple_contact 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.rdoc +37 -2
  4. data/app/controllers/simple_contact/application_controller.rb +2 -4
  5. data/app/controllers/simple_contact/contact_controller.rb +12 -16
  6. data/app/mailers/simple_contact/contact_mailer.rb +4 -6
  7. data/app/models/simple_contact/message.rb +13 -15
  8. data/config/routes.rb +1 -0
  9. data/lib/simple_contact/version.rb +1 -1
  10. data/test/controllers/contact_controller_test.rb +33 -0
  11. data/test/dummy/db/development.sqlite3 +0 -0
  12. data/test/dummy/db/test.sqlite3 +0 -0
  13. data/test/dummy/log/development.log +5 -0
  14. data/test/dummy/log/test.log +1619 -0
  15. data/test/factories/messages.rb +10 -0
  16. data/test/mailers/contact_mailer_test.rb +25 -0
  17. data/test/models/message_test.rb +42 -0
  18. data/test/test_helper.rb +9 -4
  19. metadata +32 -24
  20. data/app/assets/javascripts/simple_contact/application.js +0 -15
  21. data/app/assets/javascripts/simple_contact/contact.js +0 -2
  22. data/app/assets/stylesheets/simple_contact/application.css +0 -13
  23. data/app/assets/stylesheets/simple_contact/contact.css +0 -4
  24. data/app/helpers/simple_contact/application_helper.rb +0 -4
  25. data/app/helpers/simple_contact/contact_helper.rb +0 -4
  26. data/test/fixtures/simple_contact/messages.yml +0 -11
  27. data/test/functional/simple_contact/contact_controller_test.rb +0 -9
  28. data/test/functional/simple_contact/contact_mailer_test.rb +0 -9
  29. data/test/integration/navigation_test.rb +0 -10
  30. data/test/unit/helpers/simple_contact/contact_helper_test.rb +0 -6
  31. data/test/unit/simple_contact/message_test.rb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 48805eb10daeba76b98108113ac409754bb0c28b
4
- data.tar.gz: da419e7115b6aace7e178d06844486890196dee0
3
+ metadata.gz: a1873e4e82ff3c48e414f717401f2397a6f8dbf3
4
+ data.tar.gz: 34c805ffaf92f29b120da0b239cb8fb3557038bb
5
5
  SHA512:
6
- metadata.gz: a8dbf994bc975361f7c78c51207241ab6cca20ac2fb6aa95f8a677fd9c9ce60677bda8c6bad74290d02ff85e2f7ed953bbf8035cc82b6a8f9d020f3f7cfdb303
7
- data.tar.gz: 97aaaf6d5ec81d4226378748865e48e5d5b99e2fec8cff97efc468a7a2d3232ed80ab8b20b23d5946ea3e32dccb820228ac1c3836513ab6bb896f89520f10ba0
6
+ metadata.gz: 479bf934a64664263e72de8362121b993115a8cb4f29d0ee4ecd7b8cef82a6b64b401684a3c8c060d20f75ef053e6df78106a23209be5da72a1aeae565ce850a
7
+ data.tar.gz: 58ccc0086b9b038f2bcee67f0f3999418cf14c8961fb278ce6c5927ccf2bbca3f3d833735c9d84f8af20ba640db9249bee8fee26dc2ce9d79dfe4fa9d3cb0faa
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2013 YOURNAME
1
+ Copyright 2013 Ben Eggett
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -1,3 +1,38 @@
1
- = SimpleContact
1
+ # Simple Contact
2
2
 
3
- This project rocks and uses MIT-LICENSE.
3
+ Provides a stupidly simple contact form with bootstrap class theming for rails
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'simple_contact'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install simple_contact
18
+
19
+ ## Usage
20
+
21
+ Using Simple Contact is Easy.
22
+
23
+ Simply mount it within your application's routes file where you want your contact form:
24
+
25
+ ```
26
+ mount SimpleContact::Engine => "/contact-mes"
27
+ ```
28
+
29
+ Make sure you have an actionmailer method setup in your environment.
30
+
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new Pull Request
@@ -1,5 +1,3 @@
1
- module SimpleContact
2
- class ApplicationController < ApplicationController
3
- layout 'application'
4
- end
1
+ class SimpleContact::ApplicationController < ApplicationController
2
+
5
3
  end
@@ -1,22 +1,18 @@
1
1
  require_dependency "simple_contact/application_controller"
2
2
 
3
- module SimpleContact
4
- class ContactController < ApplicationController
5
- def new
6
- @message = SimpleContact::Message.new
7
- end
3
+ class SimpleContact::ContactController < SimpleContact::ApplicationController
4
+ def new
5
+ @message = SimpleContact::Message.new
6
+ end
8
7
 
9
- def create
10
- @message = SimpleContact::Message.new(params[:message])
11
- if @message.valid?
12
- ContactMailer.contact_message(@message).deliver
13
- redirect_to main_app.root_path, notice: I18n.translate(:mailer_success_message)
14
- else
15
- flash.now.alert = "#{I18n.translate(:mailer_error_message)}"
16
- render :new
17
- end
8
+ def create
9
+ @message = SimpleContact::Message.new(params[:message])
10
+ if @message.valid?
11
+ SimpleContact::ContactMailer.contact_message(@message).deliver
12
+ redirect_to main_app.root_path, notice: I18n.translate(:mailer_success_message)
13
+ else
14
+ flash.now.alert = "#{I18n.translate(:mailer_error_message)}"
15
+ render :new
18
16
  end
19
17
  end
20
-
21
-
22
18
  end
@@ -1,8 +1,6 @@
1
- module SimpleContact
2
- class ContactMailer < ActionMailer::Base
3
- def contact_message(message)
4
- @message = message
5
- mail(to: ENV['SIMPLE_CONTACT_TO_EMAIL'], from: @message.email, subject: "#{ENV['SIMPLE_CONTACT_SUBJECT_PREFIX']} #{@message.subject}" )
6
- end
1
+ class SimpleContact::ContactMailer < ActionMailer::Base
2
+ def contact_message(message)
3
+ @message = message
4
+ mail(to: ENV['SIMPLE_CONTACT_TO_EMAIL'], from: @message.email, subject: "#{ENV['SIMPLE_CONTACT_SUBJECT_PREFIX']} #{@message.subject}" )
7
5
  end
8
6
  end
@@ -1,23 +1,21 @@
1
- module SimpleContact
2
- class Message
1
+ class SimpleContact::Message
3
2
 
4
- include ActiveModel::Validations
5
- include ActiveModel::Conversion
6
- extend ActiveModel::Naming
3
+ include ActiveModel::Validations
4
+ include ActiveModel::Conversion
5
+ extend ActiveModel::Naming
7
6
 
8
- attr_accessor :body, :email, :name, :subject
7
+ attr_accessor :body, :email, :name, :subject
9
8
 
10
- validates :body, :subject, :name, :email, presence: true
11
- validates :email, format: { with: /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/ }
9
+ validates :body, :subject, :name, :email, presence: true
10
+ validates :email, format: { with: /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/ }
12
11
 
13
- def initialize(attributes = {})
14
- attributes.each do |name, value|
15
- send("#{name}=", value)
16
- end
12
+ def initialize(attributes = {})
13
+ attributes.each do |name, value|
14
+ send("#{name}=", value)
17
15
  end
16
+ end
18
17
 
19
- def persisted?
20
- false
21
- end
18
+ def persisted?
19
+ false
22
20
  end
23
21
  end
data/config/routes.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  SimpleContact::Engine.routes.draw do
2
+ root to: 'contact#new'
2
3
  get "/", to: 'contact#new', as: :contact
3
4
  post "/", to: 'contact#create', as: :contact
4
5
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleContact
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -0,0 +1,33 @@
1
+ require 'test_helper'
2
+
3
+ class SimpleContact::ContactControllerTest < ActionController::TestCase
4
+
5
+ before do
6
+ @routes = SimpleContact::Engine.routes
7
+ ENV['SIMPLE_CONTACT_TO_EMAIL'] = 'test@gmail.com'
8
+ ENV['SIMPLE_CONTACT_SUBJECT_PREFIX'] = "[Simple Contact]"
9
+ end
10
+
11
+
12
+ test "displays the new contact us page correctly" do
13
+ get :new
14
+ assert_response :success
15
+ assert_template :new
16
+ end
17
+
18
+ test "sends a contact email and redirects to the home page and displays a notice to the user" do
19
+ message_attributes = attributes_for(:message)
20
+ post :create, message: message_attributes
21
+ # Test that the email is actually being sent.
22
+ assert_equal ActionMailer::Base.deliveries.last.from.pop, message_attributes[:email]
23
+ assert_response :redirect
24
+ assert_redirected_to '/'
25
+ assert flash[:notice].present?
26
+ end
27
+
28
+ test "doesn't send a message & renders the new template for invalid messages" do
29
+ post :create, message: attributes_for(:message, email: nil)
30
+ assert_response :success
31
+ assert_template :new
32
+ end
33
+ end
Binary file
File without changes
@@ -6841,3 +6841,8 @@ Started GET "/assets/home.js?body=1" for 127.0.0.1 at 2013-11-22 17:53:21 -0700
6841
6841
  Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2013-11-22 17:53:21 -0700
6842
6842
  Served asset /home.js - 304 Not Modified (0ms)
6843
6843
  Served asset /application.js - 304 Not Modified (0ms)
6844
+ Connecting to database specified by database.yml
6845
+  (0.0ms) select sqlite_version(*)
6846
+  (3.2ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
6847
+  (0.7ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
6848
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations"