simple_contact 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.rdoc +37 -2
- data/app/controllers/simple_contact/application_controller.rb +2 -4
- data/app/controllers/simple_contact/contact_controller.rb +12 -16
- data/app/mailers/simple_contact/contact_mailer.rb +4 -6
- data/app/models/simple_contact/message.rb +13 -15
- data/config/routes.rb +1 -0
- data/lib/simple_contact/version.rb +1 -1
- data/test/controllers/contact_controller_test.rb +33 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +5 -0
- data/test/dummy/log/test.log +1619 -0
- data/test/factories/messages.rb +10 -0
- data/test/mailers/contact_mailer_test.rb +25 -0
- data/test/models/message_test.rb +42 -0
- data/test/test_helper.rb +9 -4
- metadata +32 -24
- data/app/assets/javascripts/simple_contact/application.js +0 -15
- data/app/assets/javascripts/simple_contact/contact.js +0 -2
- data/app/assets/stylesheets/simple_contact/application.css +0 -13
- data/app/assets/stylesheets/simple_contact/contact.css +0 -4
- data/app/helpers/simple_contact/application_helper.rb +0 -4
- data/app/helpers/simple_contact/contact_helper.rb +0 -4
- data/test/fixtures/simple_contact/messages.yml +0 -11
- data/test/functional/simple_contact/contact_controller_test.rb +0 -9
- data/test/functional/simple_contact/contact_mailer_test.rb +0 -9
- data/test/integration/navigation_test.rb +0 -10
- data/test/unit/helpers/simple_contact/contact_helper_test.rb +0 -6
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1873e4e82ff3c48e414f717401f2397a6f8dbf3
|
4
|
+
data.tar.gz: 34c805ffaf92f29b120da0b239cb8fb3557038bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 479bf934a64664263e72de8362121b993115a8cb4f29d0ee4ecd7b8cef82a6b64b401684a3c8c060d20f75ef053e6df78106a23209be5da72a1aeae565ce850a
|
7
|
+
data.tar.gz: 58ccc0086b9b038f2bcee67f0f3999418cf14c8961fb278ce6c5927ccf2bbca3f3d833735c9d84f8af20ba640db9249bee8fee26dc2ce9d79dfe4fa9d3cb0faa
|
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -1,3 +1,38 @@
|
|
1
|
-
|
1
|
+
# Simple Contact
|
2
2
|
|
3
|
-
|
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,22 +1,18 @@
|
|
1
1
|
require_dependency "simple_contact/application_controller"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
3
|
+
class SimpleContact::ContactController < SimpleContact::ApplicationController
|
4
|
+
def new
|
5
|
+
@message = SimpleContact::Message.new
|
6
|
+
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
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
|
-
|
2
|
-
class Message
|
1
|
+
class SimpleContact::Message
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
include ActiveModel::Validations
|
4
|
+
include ActiveModel::Conversion
|
5
|
+
extend ActiveModel::Naming
|
7
6
|
|
8
|
-
|
7
|
+
attr_accessor :body, :email, :name, :subject
|
9
8
|
|
10
|
-
|
11
|
-
|
9
|
+
validates :body, :subject, :name, :email, presence: true
|
10
|
+
validates :email, format: { with: /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/ }
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
12
|
+
def initialize(attributes = {})
|
13
|
+
attributes.each do |name, value|
|
14
|
+
send("#{name}=", value)
|
17
15
|
end
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
end
|
18
|
+
def persisted?
|
19
|
+
false
|
22
20
|
end
|
23
21
|
end
|
data/config/routes.rb
CHANGED
@@ -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
|
+
[1m[36m (0.0ms)[0m [1mselect sqlite_version(*)[0m
|
6846
|
+
[1m[35m (3.2ms)[0m CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
|
6847
|
+
[1m[36m (0.7ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
6848
|
+
[1m[35m (0.1ms)[0m SELECT "schema_migrations"."version" FROM "schema_migrations"
|