aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/info_request.rb3
-rw-r--r--app/models/info_request_batch.rb20
-rw-r--r--app/models/outgoing_message.rb1
-rw-r--r--app/models/public_body.rb1
-rw-r--r--app/models/user.rb2
-rw-r--r--db/migrate/20131024114346_create_info_request_batches.rb22
-rw-r--r--spec/factories.rb4
-rw-r--r--spec/models/info_request_batch_spec.rb21
8 files changed, 74 insertions, 0 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index a79ede809..3c3afe0ea 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -1,5 +1,6 @@
# encoding: utf-8
# == Schema Information
+# Schema version: 20131024114346
#
# Table name: info_requests
#
@@ -21,6 +22,7 @@
# external_url :string(255)
# attention_requested :boolean default(FALSE)
# comments_allowed :boolean default(TRUE), not null
+# info_request_batch_id :integer
#
require 'digest/sha1'
@@ -40,6 +42,7 @@ class InfoRequest < ActiveRecord::Base
validate :must_be_internal_or_external
belongs_to :public_body, :counter_cache => true
+ belongs_to :info_request_batch
validates_presence_of :public_body_id, :unless => Proc.new { |info_request| info_request.is_batch_request_template? }
has_many :outgoing_messages, :order => 'created_at'
diff --git a/app/models/info_request_batch.rb b/app/models/info_request_batch.rb
new file mode 100644
index 000000000..af6956095
--- /dev/null
+++ b/app/models/info_request_batch.rb
@@ -0,0 +1,20 @@
+# == Schema Information
+# Schema version: 20131024114346
+#
+# Table name: info_request_batches
+#
+# id :integer not null, primary key
+# title :text not null
+# user_id :integer not null
+# created_at :datetime
+# updated_at :datetime
+#
+
+class InfoRequestBatch < ActiveRecord::Base
+ has_many :info_requests
+ belongs_to :user
+
+ validates_presence_of :user
+ validates_presence_of :title
+
+end
diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb
index 8d8322b17..7132ee223 100644
--- a/app/models/outgoing_message.rb
+++ b/app/models/outgoing_message.rb
@@ -1,4 +1,5 @@
# == Schema Information
+# Schema version: 20131024114346
#
# Table name: outgoing_messages
#
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index 8e474c797..2939a7f29 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
# == Schema Information
+# Schema version: 20131024114346
#
# Table name: public_bodies
#
diff --git a/app/models/user.rb b/app/models/user.rb
index 2052b942b..730550301 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1,4 +1,5 @@
# == Schema Information
+# Schema version: 20131024114346
#
# Table name: users
#
@@ -20,6 +21,7 @@
# email_bounce_message :text default(""), not null
# no_limit :boolean default(FALSE), not null
# receive_email_alerts :boolean default(TRUE), not null
+# can_make_batch_requests :boolean default(FALSE), not null
#
require 'digest/sha1'
diff --git a/db/migrate/20131024114346_create_info_request_batches.rb b/db/migrate/20131024114346_create_info_request_batches.rb
new file mode 100644
index 000000000..09c6f467b
--- /dev/null
+++ b/db/migrate/20131024114346_create_info_request_batches.rb
@@ -0,0 +1,22 @@
+class CreateInfoRequestBatches < ActiveRecord::Migration
+ def up
+ create_table :info_request_batches do |t|
+ t.column :title, :text, :null => false
+ t.column :user_id, :integer, :null => false
+ t.timestamps
+ end
+ add_column :info_requests, :info_request_batch_id, :integer, :null => true
+ if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
+ execute "ALTER TABLE info_requests
+ ADD CONSTRAINT fk_info_requests_info_request_batch
+ FOREIGN KEY (info_request_batch_id) REFERENCES info_request_batches(id)"
+ end
+ add_index :info_requests, :info_request_batch_id
+ add_index :info_request_batches, :user_id
+ end
+
+ def down
+ remove_column :info_requests, :info_request_batch_id
+ drop_table :info_request_batches
+ end
+end
diff --git a/spec/factories.rb b/spec/factories.rb
index 189fb02cb..66388af6e 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -145,4 +145,8 @@ FactoryGirl.define do
track_query 'Example Query'
end
+ factory :info_request_batch do
+ title "Example title"
+ user
+ end
end
diff --git a/spec/models/info_request_batch_spec.rb b/spec/models/info_request_batch_spec.rb
new file mode 100644
index 000000000..f6d9bea0c
--- /dev/null
+++ b/spec/models/info_request_batch_spec.rb
@@ -0,0 +1,21 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe InfoRequestBatch, "when validating" do
+
+ before do
+ @info_request_batch = FactoryGirl.build(:info_request_batch)
+ end
+
+ it 'should require a user' do
+ @info_request_batch.user = nil
+ @info_request_batch.valid?.should be_false
+ @info_request_batch.errors.full_messages.should == ["User can't be blank"]
+ end
+
+ it 'should require a title' do
+ @info_request_batch.title = nil
+ @info_request_batch.valid?.should be_false
+ @info_request_batch.errors.full_messages.should == ["Title can't be blank"]
+ end
+
+end