forked from runtimerevolution/survey
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add predefined values to question, to be able to add a range question…
… type
- Loading branch information
1 parent
0118fb6
commit 3e67b50
Showing
13 changed files
with
126 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class Survey::PredefinedValue < ActiveRecord::Base | ||
|
||
self.table_name = "survey_predefined_values" | ||
|
||
#relations | ||
belongs_to :question | ||
|
||
#rails 3 attr_accessible support | ||
if Rails::VERSION::MAJOR < 4 | ||
attr_accessible :head_number, :name, :locale_name, :question_id | ||
end | ||
|
||
# validations | ||
validates :name, :presence => true | ||
|
||
def to_s | ||
self.name | ||
end | ||
|
||
def name | ||
I18n.locale == I18n.default_locale ? super : locale_name || super | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
lib/generators/templates/migration_create_predefined_values_table.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class CreatePredefinedValuesTable < ActiveRecord::Migration | ||
def change | ||
create_table :survey_predefined_values do |t| | ||
t.string :head_number | ||
t.string :name | ||
t.string :locale_name | ||
t.integer :question_id | ||
|
||
t.timestamps | ||
end | ||
|
||
add_column :survey_answers, :predefined_value_id, :integer | ||
end | ||
end |
14 changes: 14 additions & 0 deletions
14
test/dummy/db/migrate/20130916102353_create_predefined_values_table.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class CreatePredefinedValuesTable < ActiveRecord::Migration | ||
def change | ||
create_table :survey_predefined_values do |t| | ||
t.string :head_number | ||
t.string :name | ||
t.string :locale_name | ||
t.integer :question_id | ||
|
||
t.timestamps | ||
end | ||
|
||
add_column :survey_answers, :predefined_value_id, :integer | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require 'test_helper' | ||
|
||
class PredefinedValueTest < ActiveSupport::TestCase | ||
|
||
test "should create a valid predefined_value" do | ||
predefined_value = create_predefined_value | ||
should_be_persisted predefined_value | ||
end | ||
|
||
test "should not create a predefined_value with a empty or nil name field" do | ||
predefined_value_a = create_predefined_value({:name => nil}) | ||
predefined_value_b = create_predefined_value({:name => ''}) | ||
|
||
should_not_be_persisted predefined_value_a | ||
should_not_be_persisted predefined_value_b | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters