Skip to content
Browse files

starting a google_forms index table

  • Loading branch information...
1 parent 81a80eb commit 6d0e028fecb42ba6a7200d155d78f177c0fcf994 @drnic drnic committed Feb 25, 2010
View
7 app/controllers/google_forms_controller.rb
@@ -1,8 +1,7 @@
class GoogleFormsController < InheritedResources::Base
- def show
- show! do |format|
- @view_form_url = "/#{@google_form.slug}"
- format.html
+ def create
+ create! do |format|
+ format.html { redirect_to google_forms_path }
end
end
end
View
14 app/models/google_form.rb
@@ -1,15 +1,11 @@
class GoogleForm < ActiveRecord::Base
- validates_presence_of :slug, :formkey
- validates_uniqueness_of :slug, :formkey
+ validates_presence_of :title, :slug, :formkey
+ validates_uniqueness_of :title, :slug, :formkey
before_create :clean_formkey
before_create :validate_formkey_is_valid
- def title
- slug
- end
-
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}")
response = Net::HTTP.new(uri.host).start {|h| h.request(req)}
response
@@ -23,6 +19,10 @@ def submit(google_form_action, params)
response
end
+ def google_form_url
+ "http://spreadsheets.google.com/viewform?formkey=#{formkey}"
+ end
+
def clean_formkey
if formkey =~ /=(.*)$/
self.formkey = $1
View
26 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.
View
1 app/views/google_forms/new.html.haml
@@ -1,5 +1,6 @@
- semantic_form_for @google_form do |f|
- f.inputs do
+ = f.input :title
= f.input :slug
= f.input :formkey, :label => 'Form Key'
View
2 app/views/google_forms/show.html.haml
@@ -1,2 +0,0 @@
-You can view the published form here:
-= link_to @view_form_url, @view_form_url
View
30 config/environment.rb
@@ -14,35 +14,7 @@
config.gem 'inherited_resources', :version => '1.0.3'
config.gem 'nokogiri'
- # Settings in config/environments/* take precedence over those specified here.
- # Application configuration should go into files in config/initializers
- # -- all .rb files in that directory are automatically loaded.
+ config.middleware.use "Rails::Rack::Static"
- # 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'
-
- # 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
View
14 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
View
3 db/schema.rb
@@ -9,13 +9,14 @@
#
# 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|
t.string "slug"
t.string "formkey"
t.datetime "created_at"
t.datetime "updated_at"
+ t.string "title"
end
create_table "sessions", :force => true do |t|
View
17 features/add_new_google_forms.feature → features/google_forms.feature
@@ -7,6 +7,7 @@ Feature: Add new google forms
Given I expect Google Form "dFRUNHpLZmZHbVRrdlpMRnlJclBLc0E6MA" to be fetched
And I am on the new forms page
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 "You can view the published form here:"
@@ -15,6 +16,7 @@ Feature: Add new google forms
Given I expect Google Form "dFRUNHpLZmZHbVRrdlpMRnlJclBLc0E6MA" to be fetched
And I am on the new forms page
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 press "Create"
Then I should see "You can view the published form here:"
@@ -23,10 +25,21 @@ Feature: Add new google forms
Given I expect Google Form "XXXX" to be invalid
And I am on the new forms page
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 press "Create"
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"
View
2 features/support/paths.rb
@@ -12,6 +12,8 @@ def path_to(page_name)
'/'
when /the new forms page/
new_google_form_path
+ when /the forms list page/
+ google_forms_path
when /"(.*)"/
$1
# Add more mappings here.
View
2 rerun.txt
@@ -1 +1 @@
-
+features/google_forms.feature:6

0 comments on commit 6d0e028

Please sign in to comment.
Something went wrong with that request. Please try again.