Skip to content

Commit

Permalink
starting a google_forms index table
Browse files Browse the repository at this point in the history
  • Loading branch information
drnic committed Feb 25, 2010
1 parent 81a80eb commit 6d0e028
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 46 deletions.
7 changes: 3 additions & 4 deletions app/controllers/google_forms_controller.rb
@@ -1,8 +1,7 @@
class GoogleFormsController < InheritedResources::Base class GoogleFormsController < InheritedResources::Base
def show def create
show! do |format| create! do |format|
@view_form_url = "/#{@google_form.slug}" format.html { redirect_to google_forms_path }
format.html
end end
end end
end end
14 changes: 7 additions & 7 deletions app/models/google_form.rb
@@ -1,15 +1,11 @@
class GoogleForm < ActiveRecord::Base class GoogleForm < ActiveRecord::Base
validates_presence_of :slug, :formkey validates_presence_of :title, :slug, :formkey
validates_uniqueness_of :slug, :formkey validates_uniqueness_of :title, :slug, :formkey
before_create :clean_formkey before_create :clean_formkey
before_create :validate_formkey_is_valid before_create :validate_formkey_is_valid


def title
slug
end

def fetch_form_page def fetch_form_page
uri = URI.parse("http://spreadsheets.google.com/viewform?formkey=#{formkey}") uri = URI.parse(google_form_url)
req = Net::HTTP::Get.new("#{uri.path}?#{uri.query}") req = Net::HTTP::Get.new("#{uri.path}?#{uri.query}")
response = Net::HTTP.new(uri.host).start {|h| h.request(req)} response = Net::HTTP.new(uri.host).start {|h| h.request(req)}
response response
Expand All @@ -23,6 +19,10 @@ def submit(google_form_action, params)
response response
end end


def google_form_url
"http://spreadsheets.google.com/viewform?formkey=#{formkey}"
end

def clean_formkey def clean_formkey
if formkey =~ /=(.*)$/ if formkey =~ /=(.*)$/
self.formkey = $1 self.formkey = $1
Expand Down
26 changes: 26 additions & 0 deletions app/views/google_forms/index.html.haml
@@ -0,0 +1,26 @@
%h2 Our forms

%p
= link_to "Add Google Form", new_google_form_path

.ss-grid
%table
%thead
%tr
%th Slug
%th Title
%th Original Form
%th Actions
%tbody
- unless @google_forms.blank?
- for form in @google_forms
%tr
%td= link_to form.slug, "/#{form.slug}"
%td= form.title
%td= link_to form.formkey, form.google_form_url
%td
= link_to "Live", "/#{form.slug}"
= link_to "Edit", edit_google_form_path(form)
- else
%tr
%td{:colspan => 4} No forms yet.
1 change: 1 addition & 0 deletions app/views/google_forms/new.html.haml
@@ -1,5 +1,6 @@
- semantic_form_for @google_form do |f| - semantic_form_for @google_form do |f|
- f.inputs do - f.inputs do
= f.input :title
= f.input :slug = f.input :slug
= f.input :formkey, :label => 'Form Key' = f.input :formkey, :label => 'Form Key'


Expand Down
2 changes: 0 additions & 2 deletions app/views/google_forms/show.html.haml

This file was deleted.

30 changes: 1 addition & 29 deletions config/environment.rb
Expand Up @@ -14,35 +14,7 @@
config.gem 'inherited_resources', :version => '1.0.3' config.gem 'inherited_resources', :version => '1.0.3'
config.gem 'nokogiri' config.gem 'nokogiri'


# Settings in config/environments/* take precedence over those specified here. config.middleware.use "Rails::Rack::Static"
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.


# Add additional load paths for your own custom dirs
# config.load_paths += %W( #{RAILS_ROOT}/extras )

# Specify gems that this application depends on and have them installed with rake gems:install
# config.gem "bj"
# config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
# config.gem "sqlite3-ruby", :lib => "sqlite3"
# config.gem "aws-s3", :lib => "aws/s3"

# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]

# Skip frameworks you're not going to use. To use Rails without a database,
# you must remove the Active Record framework.
# config.frameworks -= [ :active_record, :active_resource, :action_mailer ]

# Activate observers that should always be running
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer

# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names.
config.time_zone = 'UTC' config.time_zone = 'UTC'

# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
# config.i18n.default_locale = :de
end end
14 changes: 14 additions & 0 deletions db/migrate/20100225054631_add_title_to_google_forms.rb
@@ -0,0 +1,14 @@
class AddTitleToGoogleForms < ActiveRecord::Migration
def self.up
add_column :google_forms, :title, :string

GoogleForm.all.each do |form|
form.title = form.slug
form.save
end
end

def self.down
remove_column :google_forms, :title
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Expand Up @@ -9,13 +9,14 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.


ActiveRecord::Schema.define(:version => 20100223004515) do ActiveRecord::Schema.define(:version => 20100225054631) do


create_table "google_forms", :force => true do |t| create_table "google_forms", :force => true do |t|
t.string "slug" t.string "slug"
t.string "formkey" t.string "formkey"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "title"
end end


create_table "sessions", :force => true do |t| create_table "sessions", :force => true do |t|
Expand Down
Expand Up @@ -7,6 +7,7 @@ Feature: Add new google forms
Given I expect Google Form "dFRUNHpLZmZHbVRrdlpMRnlJclBLc0E6MA" to be fetched Given I expect Google Form "dFRUNHpLZmZHbVRrdlpMRnlJclBLc0E6MA" to be fetched
And I am on the new forms page And I am on the new forms page
When I fill in "Slug" with "railsdev" When I fill in "Slug" with "railsdev"
And I fill in "Title" with "Apply for Rails Developer Job"
And I fill in "Form Key" with "http://spreadsheets.google.com/viewform?formkey=dFRUNHpLZmZHbVRrdlpMRnlJclBLc0E6MA" And I fill in "Form Key" with "http://spreadsheets.google.com/viewform?formkey=dFRUNHpLZmZHbVRrdlpMRnlJclBLc0E6MA"
And I press "Create" And I press "Create"
Then I should see "You can view the published form here:" Then I should see "You can view the published form here:"
Expand All @@ -15,6 +16,7 @@ Feature: Add new google forms
Given I expect Google Form "dFRUNHpLZmZHbVRrdlpMRnlJclBLc0E6MA" to be fetched Given I expect Google Form "dFRUNHpLZmZHbVRrdlpMRnlJclBLc0E6MA" to be fetched
And I am on the new forms page And I am on the new forms page
When I fill in "Slug" with "railsdev" When I fill in "Slug" with "railsdev"
And I fill in "Title" with "Apply for Rails Developer Job"
And I fill in "Form Key" with "dFRUNHpLZmZHbVRrdlpMRnlJclBLc0E6MA" And I fill in "Form Key" with "dFRUNHpLZmZHbVRrdlpMRnlJclBLc0E6MA"
And I press "Create" And I press "Create"
Then I should see "You can view the published form here:" Then I should see "You can view the published form here:"
Expand All @@ -23,10 +25,21 @@ Feature: Add new google forms
Given I expect Google Form "XXXX" to be invalid Given I expect Google Form "XXXX" to be invalid
And I am on the new forms page And I am on the new forms page
When I fill in "Slug" with "railsdev" When I fill in "Slug" with "railsdev"
And I fill in "Title" with "Apply for Rails Developer Job"
And I fill in "Form Key" with "XXXX" And I fill in "Form Key" with "XXXX"
And I press "Create" And I press "Create"
Then I should see "is not a valid Google Forms key or URL" Then I should see "is not a valid Google Forms key or URL"



Scenario: List of forms

Given I am on the forms list page
Then I should see "No forms yet."
When I follow "Add Google Form"
Given I expect Google Form "dFRUNHpLZmZHbVRrdlpMRnlJclBLc0E6MA" to be fetched
When I fill in "Slug" with "railsdev"
And I fill in "Title" with "Apply for Rails Developer Job"
And I fill in "Form Key" with "http://spreadsheets.google.com/viewform?formkey=dFRUNHpLZmZHbVRrdlpMRnlJclBLc0E6MA"
And I press "Create"
Then I should see "Apply for Rails Developer Job"
Given I am on the home page
Then I should see "Apply for Rails Developer Job"


2 changes: 2 additions & 0 deletions features/support/paths.rb
Expand Up @@ -12,6 +12,8 @@ def path_to(page_name)
'/' '/'
when /the new forms page/ when /the new forms page/
new_google_form_path new_google_form_path
when /the forms list page/
google_forms_path
when /"(.*)"/ when /"(.*)"/
$1 $1
# Add more mappings here. # Add more mappings here.
Expand Down
2 changes: 1 addition & 1 deletion rerun.txt
@@ -1 +1 @@

features/google_forms.feature:6

0 comments on commit 6d0e028

Please sign in to comment.