Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

made everything that was being stored in json format in the database …

…serializable
  • Loading branch information...
commit b5c11d09789a7f196bf0026e2de493e19afdb9f7 1 parent b8c38a8
@TiagoCardoso1983 authored
Showing with 228 additions and 121 deletions.
  1. +2 −2 app/controllers/application_controller.rb
  2. +2 −2 app/controllers/statements/statement_images_controller.rb
  3. +3 −4 app/controllers/users/activations_controller.rb
  4. +10 −10 app/controllers/users/social_module.rb
  5. +9 −9 app/controllers/users/user_sessions_controller.rb
  6. +1 −1  app/controllers/users/users_controller.rb
  7. +5 −5 app/helpers/mail_helper.rb
  8. +1 −0  app/models/pending_action.rb
  9. +2 −1  app/models/shortcut_command.rb
  10. +2 −2 app/models/shortcut_url.rb
  11. +1 −1  app/models/statements/statement.rb
  12. +6 −6 app/views/activity_tracking_mailer/_operation_template.html.erb
  13. +1 −1  app/views/activity_tracking_mailer/activity_templates/_root_statements_activity_template.html.erb
  14. +1 −1  app/views/activity_tracking_mailer/activity_templates/_statement_activity_template.html.erb
  15. +105 −0 db/migrate/20120225183159_change_string_to_text_attributes_on_models_that_serialize.rb
  16. +6 −6 db/schema.rb
  17. +4 −5 features/step_definitions/discuss_steps.rb
  18. +12 −12 lib/activity_tracking_service/activity_tracking_service.rb
  19. +2 −0  lib/activity_tracking_service/event.rb
  20. +1 −1  lib/social_service/acts_as_social.rb
  21. +1 −1  lib/social_service/social_identifier.rb
  22. +2 −2 lib/social_service/social_service.rb
  23. +4 −4 test/fixtures/events.yml
  24. +2 −2 test/fixtures/social_identifiers.yml
  25. +4 −4 test/functional/activations_controller_test.rb
  26. +5 −5 test/functional/users_controller_test.rb
  27. +23 −23 test/unit/activity_tracking_mailer_test.rb
  28. +8 −8 test/unit/shortcut_url_test.rb
  29. +1 −1  test/unit/statement_node_test.rb
  30. +2 −2 test/unit/user_test.rb
View
4 app/controllers/application_controller.rb
@@ -537,8 +537,8 @@ def log_message_error(e, message)
def shortcut
begin
shortcut = ShortcutUrl.find(params[:shortcut])
- command = JSON.parse(shortcut.command)
- url = send("#{command['operation']}_path", command['params'].merge({:locale => command['language']}))
+ command = shortcut.command
+ url = send("#{command[:operation]}_path", command[:params].merge({:locale => command[:language]}))
redirect_to url
rescue ActiveRecord::RecordNotFound
redirect_to discuss_search_url(:search_terms => params[:shortcut])
View
4 app/controllers/statements/statement_images_controller.rb
@@ -32,7 +32,7 @@ def new
#
def create
image = StatementImage.create(params[:statement_image])
- PendingAction.find(params[:pending_action_id]).update_attributes(:action => {:image_id => image.id}.to_json)
+ PendingAction.find(params[:pending_action_id]).update_attributes(:action => {:image_id => image.id})
respond_to(:html,:js)
end
@@ -75,7 +75,7 @@ def update
#
def load
@pending = PendingAction.find(params[:id])
- @statement_image = StatementImage.find(JSON.parse(@pending.action)['image_id'])
+ @statement_image = StatementImage.find(@pending.action[:image_id])
respond_to do |format|
if @statement_image.image.exists?
set_info 'discuss.messages.image_uploaded', :type => I18n.t("discuss.statements.types.#{params[:type]}")
View
7 app/controllers/users/activations_controller.rb
@@ -39,7 +39,7 @@ def activate
redirect_or_render_with_error(base_url, "users.activation.messages.no_account")
return
elsif via_form # Coming from setup basic profile form
- if params[:user].delete(:agreement).nil?
+ if params[:user].delete(:agreement).blank?
redirect_or_render_with_error(base_url, "users.activation.messages.no_agreement")
return
elsif params[:user][:full_name].try(:strip).blank?
@@ -51,8 +51,7 @@ def activate
redirect_or_render_with_error(base_url, "users.activation.messages.already_active")
return
end
-
-
+
if @user.email or @user.has_verified_email? params[:user][:email]
# Given email is a verified email, therefore, no activation is needed
if @user.activate!(params[:user]) and @user.profile.save # so that the name persists
@@ -106,7 +105,7 @@ def activate_email
else
@user = @action.pending
User.transaction do
- if @user.update_attributes(JSON.parse(@action.action))
+ if @user.update_attributes(@action.action)
@action.update_attribute(:status, true)
UserSession.create(@user, false)
@user.deliver_activation_confirmation!
View
20 app/controllers/users/social_module.rb
@@ -12,13 +12,13 @@ def create_social
@user = User.new
opts ={}
- opts = {:social_identifiers => [SocialIdentifier.new(:identifier => profile_info['identifier'],
- :provider_name => profile_info['providerName'],
- :profile_info => profile_info.to_json )] }
+ opts = {:social_identifiers => [SocialIdentifier.new(:identifier => profile_info[:identifier],
+ :provider_name => profile_info[:providerName],
+ :profile_info => profile_info )] }
User.transaction do
if @user.signup!(opts)
- SocialService.instance.map(profile_info['identifier'], @user.id)
+ SocialService.instance.map(profile_info[:identifier], @user.id)
later_call_with_info(redirect_url, setup_basic_profile_url(@user.perishable_token))
else
later_call_with_error(redirect_url, signup_url, @user.social_identifiers.first)
@@ -47,7 +47,7 @@ def create_social
#
def setup_basic_profile
@user = User.find_by_perishable_token(params[:activation_code], 1.week)
- @profile_info = JSON.parse(@user.social_identifiers.first.profile_info)
+ @profile_info = @user.social_identifiers.first.profile_info
if @user.nil?
redirect_or_render_with_error(base_url, "users.activation.messages.no_account")
elsif @user.active?
@@ -73,12 +73,12 @@ def add_social
if params[:token]
User.transaction do
profile_info = SocialService.instance.get_profile_info(params[:token])
- social_id = current_user.add_social_identifier(profile_info['identifier'],
- profile_info['providerName'],
- profile_info.to_json )
- account_name = I18n.t("users.social_accounts.providers.#{profile_info['providerName'].downcase}")
+ social_id = current_user.add_social_identifier(profile_info[:identifier],
+ profile_info[:providerName],
+ profile_info )
+ account_name = I18n.t("users.social_accounts.providers.#{profile_info[:providerName].downcase}")
if social_id.save
- SocialService.instance.map(profile_info['identifier'], current_user.id)
+ SocialService.instance.map(profile_info[:identifier], current_user.id)
if later_call_url
later_call_with_info(redirect_url,
later_call_url,
View
18 app/controllers/users/user_sessions_controller.rb
@@ -40,16 +40,16 @@ def create_social
profile_info = SocialService.instance.get_profile_info(params[:token])
user = nil
User.transaction do
- if profile_info['primaryKey'].nil? or (user = User.find(profile_info['primaryKey'])).nil?
- session[:identifier] = profile_info.to_json
- invalid_social = SocialIdentifier.find_by_identifier(profile_info['identifier'])
+ if profile_info[:primaryKey].nil? or (user = User.find(profile_info[:primaryKey])).nil?
+ session[:identifier] = profile_info
+ invalid_social = SocialIdentifier.find_by_identifier(profile_info[:identifier])
invalid_social.destroy if invalid_social
later_call_with_error(redirect_url, signin_path, 'users.signin.messages.failed_social')
else
- if social = user.identified_by?(profile_info['identifier'])
- social.update_attribute(:profile_info, profile_info.to_json)
+ if social = user.identified_by?(profile_info[:identifier])
+ social.update_attribute(:profile_info, profile_info)
else
- user.add_social_identifier( profile_info['identifier'], profile_info['providerName'], profile_info.to_json )
+ user.add_social_identifier( profile_info[:identifier], profile_info[:providerName], profile_info )
end
if user.active? # user was already actived, i.e. he has an email account defined
@user_session = UserSession.new(user)
@@ -88,9 +88,9 @@ def destroy
protected
def add_social_to_user(user)
- profile_info = JSON.parse(session[:identifier])
- social_identifier = SocialIdentifier.create(:identifier => profile_info['identifier'],
- :provider_name => profile_info['providerName'],
+ profile_info = session[:identifier]
+ social_identifier = SocialIdentifier.create(:identifier => profile_info[:identifier],
+ :provider_name => profile_info[:providerName],
:profile_info => session[:identifier],
:user => user)
session.delete(:identifier)
View
2  app/controllers/users/users_controller.rb
@@ -118,7 +118,7 @@ def update_email
else
# Validate per Mail and change in a pending action
- pending_action = PendingAction.create(:action => params[:user].to_json, :pending => current_user)
+ pending_action = PendingAction.create(:action => params[:user], :pending => current_user)
current_user.deliver_activate_email!(params[:user][:email], pending_action.uuid)
redirect_or_render_with_info(settings_path, "users.users.messages.activate_email") do |page|
close_panel(page)
View
10 app/helpers/mail_helper.rb
@@ -24,19 +24,19 @@ def get_document_in_preferred_language(documents, language_ids)
end
def inline_statement_link(document, event)
- if event['info_type']
- image_name = 'bi_' + event['info_type']
+ if event[:info_type]
+ image_name = 'bi_' + event[:info_type]
else
- image_name = event['type']
+ image_name = event[:type]
end
icon_url = full_url("/images/page/discuss/statement_icons/#{image_name}.png")
content_tag(:li,
- :class => "statement_link #{event['type']}_link",
+ :class => "statement_link #{event[:type]}_link",
:style => "list-style: none; margin: 7px 0;") do
concat(
image_tag(icon_url, :alt => '') +
link_to(document[1],
- statement_node_url(event['id'], :locale => Language[document[0].to_i].code),
+ statement_node_url(event[:id], :locale => Language[document[0].to_i].code),
:style => "color: #21587f; text-decoration: none; font-weight: bold; padding-left: 5px; vertical-align: top;")
)
end
View
1  app/models/pending_action.rb
@@ -1,6 +1,7 @@
class PendingAction < ActiveRecord::Base
include UUIDHelper
belongs_to :pending, :polymorphic => true
+ serialize :action, Hash
set_primary_key 'uuid'
View
3  app/models/shortcut_command.rb
@@ -1,5 +1,6 @@
class ShortcutCommand < ActiveRecord::Base
has_many :shortcut_urls, :dependent => :destroy
+ serialize :command, Hash
validates_uniqueness_of :command
@@ -8,7 +9,7 @@ class << self
def build_command(opts)
{:operation => opts[:operation],
:params => opts[:params],
- :language => opts[:language]}.to_json
+ :language => opts[:language]}
end
end
View
4 app/models/shortcut_url.rb
@@ -2,7 +2,7 @@ class ShortcutUrl < ActiveRecord::Base
belongs_to :shortcut_command
set_primary_key 'shortcut'
- delegate :command, :to => :shortcut_command
+ delegate :command, :to => :shortcut_command, :allow_nil => true
validates_length_of :shortcut, :maximum => 101
@@ -33,7 +33,7 @@ def find_or_create(opts={})
opts[:shortcut] = shortcut
s = self.new
- s.shortcut_command = ShortcutCommand.find_by_command(shortcut_command[:command]) || ShortcutCommand.new(shortcut_command)
+ s.shortcut_command = ShortcutCommand.find_by_command(shortcut_command[:command].to_yaml) || ShortcutCommand.new(shortcut_command)
opts.each {|k,v| s.send("#{k}=", v)}
s.save ? s : nil
end
View
2  app/models/statements/statement.rb
@@ -70,7 +70,7 @@ def has_author? user
def statement_image_id=(image_id)
return if image_id.blank?
@pending_image = PendingAction.find(image_id)
- self.statement_image = StatementImage.find(JSON.parse(@pending_image.action)['image_id'])
+ self.statement_image = StatementImage.find(@pending_image.action[:image_id])
end
View
12 app/views/activity_tracking_mailer/_operation_template.html.erb
@@ -1,20 +1,20 @@
<% if !events.empty? %>
<% events.each_with_index do |event, index| %>
<% if index == 0 %>
- <% parent_document = get_document_in_preferred_language(event["parent_documents"], @preferred_language_ids) %>
+ <% parent_document = get_document_in_preferred_language(event[:parent_documents], @preferred_language_ids) %>
<%= content_tag :p, I18n.t("mailers.activity_tracking.statements.#{operation}_#{type.pluralize}",
:title => parent_document[1],
:locale => @language.code) if render_level == 0 %>
<ul style="padding-left: 20px;">
<% end %>
- <% children_level = @events[event['level']+1] %>
- <% @events[event['level']][event['parent_id']][event['type']][event['operation']] -= [event] %>
+ <% children_level = @events[event[:level]+1] %>
+ <% @events[event[:level]][event[:parent_id]][event[:type]][event[:operation]] -= [event] %>
<%= render :partial => "activity_tracking_mailer/activity_templates/statement_activity_template",
:locals => {:event => event} %>
<%= render :partial => "activity_tracking_mailer/children_template",
- :locals => {:parent_id => event['id'],
- :events => children_level[event['id']],
- :render_level => render_level + 1} if children_level and children_level[event['id']] %>
+ :locals => {:parent_id => event[:id],
+ :events => children_level[event[:id]],
+ :render_level => render_level + 1} if children_level and children_level[event[:id]] %>
<% end %>
</ul>
<% end %>
View
2  ...s/activity_tracking_mailer/activity_templates/_root_statements_activity_template.html.erb
@@ -16,7 +16,7 @@
<ul style="padding-left: 20px;">
<% @root_events.each do |event| %>
- <% document = get_document_in_preferred_language(event["documents"], @preferred_language_ids) %>
+ <% document = get_document_in_preferred_language(event[:documents], @preferred_language_ids) %>
<%= inline_statement_link(document, event) %>
<% end %>
</ul>
View
2  app/views/activity_tracking_mailer/activity_templates/_statement_activity_template.html.erb
@@ -1,4 +1,4 @@
-<% document = get_document_in_preferred_language(event["documents"], @preferred_language_ids) %>
+<% document = get_document_in_preferred_language(event[:documents], @preferred_language_ids) %>
<%= inline_statement_link(document, event) %>
View
105 db/migrate/20120225183159_change_string_to_text_attributes_on_models_that_serialize.rb
@@ -0,0 +1,105 @@
+class ChangeStringToTextAttributesOnModelsThatSerialize < ActiveRecord::Migration
+ def self.up
+ # Shortcut Command
+ rename_column :shortcut_commands, :command, :old_command
+ add_column :shortcut_commands, :command, :text
+
+ ShortcutCommand.find_each do |sh|
+ command = JSON.parse(sh.old_command)
+ command.symbolize_keys!
+ sh.command = command
+ sh.save
+ print '.'
+ end
+ remove_column :shortcut_commands, :old_command
+
+ # Shortcut Command
+ rename_column :pending_actions, :action, :old_action
+ add_column :pending_actions, :action, :text
+
+ PendingAction.find_each do |pa|
+ action = JSON.parse(pa.old_action)
+ action.symbolize_keys!
+ pa.action = action
+ pa.save
+ print '.'
+ end
+ remove_column :pending_actions, :old_action
+
+ # Event
+ rename_column :events, :event, :old_event
+ add_column :events, :event, :text
+
+ Event.find_each do |e|
+ event = JSON.parse(e.old_event)
+ event.symbolize_keys!
+ e.event = event
+ e.save
+ print '.'
+ end
+ remove_column :events, :old_event
+
+ # Social Identifier
+ rename_column :social_identifiers, :profile_info, :old_profile_info
+ add_column :social_identifiers, :profile_info, :text
+
+ SocialIdentifier.find_each do |si|
+ profile_info = JSON.parse(si.old_profile_info)
+ profile_info.symbolize_keys!
+ si.profile_info = profile_info
+ si.save
+ print '.'
+ end
+ remove_column :social_identifiers, :old_profile_info
+ end
+
+ def self.down
+ # Shortcut Command
+ rename_column :shortcut_commands, :command, :old_command
+ add_column :shortcut_commands, :command, :text
+
+ ShortcutCommand.find_each do |sh|
+ command = sh.old_command
+ sh.command = command.to_json
+ sh.save
+ print '.'
+ end
+ remove_column :shortcut_commands, :old_command
+
+ # Shortcut Command
+ rename_column :pending_actions, :action, :old_action
+ add_column :pending_actions, :action, :text
+
+ PendingAction.find_each do |pa|
+ action = pa.old_action
+ pa.action = action.to_json
+ pa.save
+ print '.'
+ end
+ remove_column :pending_actions, :old_action
+
+ # Event
+ rename_column :events, :event, :old_event
+ add_column :events, :event, :text
+
+ Event.find_each do |e|
+ event = e.old_event
+ e.event = event.to_json
+ e.save
+ print '.'
+ end
+ remove_column :events, :old_event
+
+ # Social Identifier
+ rename_column :social_identifiers, :profile_info, :old_profile_info
+ add_column :social_identifiers, :profile_info, :text
+
+ SocialIdentifier.find_each do |si|
+ profile_info = si.old_profile_info
+ si.profile_info = profile_info.to_json
+ si.save
+ print '.'
+ end
+ remove_column :social_identifiers, :old_profile_info
+ end
+end
View
12 db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110814114718) do
+ActiveRecord::Schema.define(:version => 20120225183159) do
create_table "about_item_translations", :force => true do |t|
t.integer "about_item_id"
@@ -85,12 +85,12 @@
add_index "enum_values", ["enum_key_id", "code", "id"], :name => "idx_enum_values_enum_key_code_pk"
create_table "events", :force => true do |t|
- t.text "event"
t.integer "subscribeable_id"
t.string "subscribeable_type"
t.string "operation"
t.datetime "created_at"
t.boolean "broadcast", :default => false
+ t.text "event"
end
add_index "events", ["subscribeable_id", "subscribeable_type", "created_at"], :name => "events_index"
@@ -136,12 +136,12 @@
create_table "pending_actions", :id => false, :force => true do |t|
t.string "uuid", :limit => 36
- t.text "action"
t.boolean "status", :default => false, :null => false
t.integer "pending_id"
t.datetime "created_at"
t.datetime "updated_at"
t.string "pending_type"
+ t.text "action"
end
create_table "profiles", :force => true do |t|
@@ -201,7 +201,7 @@
add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
create_table "shortcut_commands", :force => true do |t|
- t.string "command"
+ t.text "command"
end
create_table "shortcut_urls", :id => false, :force => true do |t|
@@ -217,10 +217,10 @@
create_table "social_identifiers", :force => true do |t|
t.string "identifier", :null => false
t.string "provider_name"
- t.text "profile_info"
t.integer "user_id", :null => false
t.datetime "created_at"
t.datetime "updated_at"
+ t.text "profile_info"
end
add_index "social_identifiers", ["identifier"], :name => "index_social_identifiers_on_identifier", :unique => true
@@ -402,7 +402,7 @@
end
add_index "web_addresses", ["user_id"], :name => "index_web_profiles_on_user_id"
-
+
create_view "statement_permissions", "select `statements`.`id` AS `statement_id`,`tao_users`.`tao_id` AS `user_id` from (((`statements` left join `tao_tags` `tao_statements` on(((`statements`.`id` = `tao_statements`.`tao_id`) and (`tao_statements`.`tao_type` = 'Statement') and (`tao_statements`.`context_id` = (select `enum_keys`.`id` from `enum_keys` where ((`enum_keys`.`type` = 'TagContext') and (`enum_keys`.`code` = 'topic'))))))) left join `tags` on((`tags`.`id` = `tao_statements`.`tag_id`))) left join `tao_tags` `tao_users` on(((`tags`.`id` = `tao_users`.`tag_id`) and (`tao_users`.`tao_type` = 'User') and (`tao_users`.`context_id` = (select `enum_keys`.`id` from `enum_keys` where ((`enum_keys`.`type` = 'TagContext') and (`enum_keys`.`code` = 'decision_making'))))))) where (substr(`tags`.`value`,1,2) = '**')", :force => true do |v|
v.column :statement_id
v.column :user_id
View
9 features/step_definitions/discuss_steps.rb
@@ -262,15 +262,14 @@
Then /^the ([^\"]*) should not have a "([^\"]*)" event$/ do |st_type, op_type|
st_type = st_type.split(' ').join('_')
statement = instance_variable_get("@#{st_type}")
- event = Event.all.select{|e|event = JSON.parse(e.event) ; event['id'].eql? statement.id and event['type'].eql? st_type}.first
- puts event.inspect
+ event = Event.all.select{|e|event = e.event ; event[:id].eql? statement.id and event[:type].eql? st_type}.first
assert event.nil?
end
Then /^the ([^\"]*) should have a "([^\"]*)" event$/ do |st_type, op_type|
st_type = st_type.split(' ').join('_')
statement = instance_variable_get("@#{st_type}")
- event = Event.all.select{|e|event = JSON.parse(e.event) ; event['id'].eql? statement.id and event['type'].eql? st_type}.first
+ event = Event.all.select{|e|event = e.event ; event[:id].eql? statement.id and event[:type].eql? st_type}.first
assert !event.nil?
assert_equal op_type, event.operation
end
@@ -280,8 +279,8 @@
variable = instance_variable_get("@#{type}")
variable.reload
event = Event.all.select{|e|
- ev = JSON.parse(e.event)
- ev['id'].eql? variable.target_id and ev['type'].eql? variable.class.name.underscore
+ ev = e.event
+ ev[:id].eql? variable.target_id and ev[:type].eql? variable.class.name.underscore
}.first
assert event.nil?
end
View
24 lib/activity_tracking_service/activity_tracking_service.rb
@@ -56,7 +56,7 @@ def incorporated(echoable, user)
#
def created_event(node)
- event_json = {
+ event = {
:operation => 'created',
:type => node.u_class_name,
:info_type => node.class.has_embeddable_data? ? node.info_type.code : nil,
@@ -67,9 +67,9 @@ def created_event(node)
:documents => set_titles_hash(node.statement_documents),
:parent_documents => node.parent_node ? set_titles_hash(node.parent_node.statement_documents) : nil,
:parent_id => node.parent_id || -1
- }.to_json
+ }
- Event.create(:event => event_json,
+ Event.create(:event => event,
:operation => 'created',
:broadcast => node.parent_node.nil? ? true : false,
:subscribeable => node.parent_node.nil? ? node : node.parent)
@@ -122,10 +122,10 @@ def generate_activity_mail(recipient_id)
# Collecting events
events = Event.find_tracked_events(recipient)
last_event = events.first
- events.map!{|e| JSON.parse(e.event)}
+ events.map!(&:event)
# Filter only events whose titles languages the recipient speaks
- events.reject!{|e| (e['documents'].keys.map{|id|id.to_i} & user_filtered_languages(recipient)).empty? }
+ events.reject!{|e| (e[:documents].keys.map{|id|id.to_i} & user_filtered_languages(recipient)).empty? }
return if events.blank? #if there are no events to send per email, take the next user
@@ -141,21 +141,21 @@ def generate_activity_mail(recipient_id)
def build_events_hash(events)
# Take the question events apart
- root_events = events.select{|e| e['level'] == 0 and e['top_level']}
+ root_events = events.select{|e| e[:level] == 0 and e[:top_level]}
events -= root_events
# Create a Hash containing the number of occurrences of the new tags in the new questions
question_tag_counts = root_events.each_with_object({}) do |root, tags_hash|
- root['tags'].each{|tag| tags_hash[tag] = tags_hash.has_key?(tag) ? tags_hash[tag] + 1 : 1 }
+ root[:tags].each{|tag| tags_hash[tag] = tags_hash.has_key?(tag) ? tags_hash[tag] + 1 : 1 }
end
# Turn array of events into an hash
events = events.each_with_object({}) do |e, hash|
- hash[e['level']] ||= {}
- hash[e['level']][e['parent_id']] ||= {}
- hash[e['level']][e['parent_id']][e['type']] ||= {}
- hash[e['level']][e['parent_id']][e['type']][e['operation']] ||= []
- hash[e['level']][e['parent_id']][e['type']][e['operation']] << e
+ hash[e[:level]] ||= {}
+ hash[e[:level]][e[:parent_id]] ||= {}
+ hash[e[:level]][e[:parent_id]][e[:type]] ||= {}
+ hash[e[:level]][e[:parent_id]][e[:type]][e[:operation]] ||= []
+ hash[e[:level]][e[:parent_id]][e[:type]][e[:operation]] << e
end
[root_events, events, question_tag_counts]
View
2  lib/activity_tracking_service/event.rb
@@ -1,5 +1,7 @@
class Event < ActiveRecord::Base
belongs_to :subscribeable, :polymorphic => true
+ serialize :event, Hash
+
# FIXME: make only one SQL and join for subscribable ids instead of using parent_id IN (?) !!!!
def self.find_tracked_events(subscriber)
View
2  lib/social_service/acts_as_social.rb
@@ -41,7 +41,7 @@ def has_provider?(provider_name)
def has_verified_email?(email)
self.social_identifiers.each do |si|
- return true if email.eql? JSON.parse(si.profile_info)['verifiedEmail']
+ return true if email.eql? si.profile_info[:verifiedEmail]
end
false
end
View
2  lib/social_service/social_identifier.rb
@@ -1,6 +1,6 @@
class SocialIdentifier < ActiveRecord::Base
validates_presence_of :identifier
validates_uniqueness_of :identifier
-
+ serialize :profile_info, Hash
belongs_to :user
end
View
4 lib/social_service/social_service.rb
@@ -30,8 +30,8 @@ def get_provider_auth_url(provider, token_url)
def load_basic_profile_options(profile_info)
- {:email => profile_info['verifiedEmail'] || profile_info['email'],
- :full_name => profile_info['displayName'] || profile_info['preferredUsername']}
+ {:email => profile_info[:verifiedEmail] || profile_info[:email],
+ :full_name => profile_info[:displayName] || profile_info[:preferredUsername]}
end
View
8 test/fixtures/events.yml
@@ -1,7 +1,7 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
event_test_question:
- event: '{"type":"question","id":<%= Fixtures.identify('test-question')%>,"tags":["#echonomyjam"],"documents":{"<%= Fixtures.identify('language_en') %>":"Test Question?"},"parent_documents":null,"parent_id":-1,"operation":"created","level":0,"top_level":true}'
+ event: <%= {:type => "question", :id => Fixtures.identify('test-question'),:tags => ["#echonomyjam"], :documents => {Fixtures.identify('language_en') => "Test Question?"}, :parent_documents=> nil, :parent_id => -1, :operation => "created", :level => 0, :top_level => true}.to_yaml.inspect %>
subscribeable_id: <%= Fixtures.identify('test-question')%>
subscribeable_type: StatementNode
operation: new
@@ -9,21 +9,21 @@ event_test_question:
event_second_proposal:
- event: '{"type":"proposal","id":<%= Fixtures.identify('second-proposal')%>,"tags":[],"documents":{"<%= Fixtures.identify('language_en') %>":"Second Proposal"},"parent_documents":{"<%= Fixtures.identify('language_en') %>":"Test Question?"},"parent_id":<%= Fixtures.identify('test-question')%>,"operation":"created","level":1,"top_level":false}'
+ event: <%= {:type => "proposal", :id => Fixtures.identify('second-proposal'), :tags => [], :documents => {Fixtures.identify('language_en') => "Second Proposal"}, :parent_documents => { Fixtures.identify('language_en') => "Test Question?"}, :parent_id => Fixtures.identify('test-question'), :operation => "created", :level => 1, :top_level => false }.to_yaml.inspect %>
subscribeable_id: <%= Fixtures.identify('test-question')%>
subscribeable_type: StatementNode
operation: new
broadcast: 0
event_first_impro_proposal:
- event: '{"type":"improvement","id":<%= Fixtures.identify('first-impro-proposal')%>,"tags":[],"documents":{"<%= Fixtures.identify('language_en') %>":"A better first proposal"},"parent_documents":{"<%= Fixtures.identify('language_en') %>":"A first proposal!","<%= Fixtures.identify('language_de') %>":"Ein erster Vorschlag"},"parent_id":<%= Fixtures.identify('first-proposal')%>,"operation":"created","level":2,"top_level":false}'
+ event: <%= {:type => "improvement", :id=> Fixtures.identify('first-impro-proposal'), :tags => [], :documents =>{Fixtures.identify('language_en') => "A better first proposal"}, :parent_documents => {Fixtures.identify('language_en') => "A first proposal!",Fixtures.identify('language_de') => "Ein erster Vorschlag"}, :parent_id => Fixtures.identify('first-proposal'), :operation => "created", :level => 2, :top_level => false}.to_yaml.inspect %>
subscribeable_id: <%= Fixtures.identify('first-proposal')%>
subscribeable_type: StatementNode
operation: new
broadcast: 0
event_closed_impro_proposal:
- event: '{"type":"improvement","id":<%= Fixtures.identify('fifth-impro-proposal')%>,"tags":[],"documents":{"<%= Fixtures.identify('language_en') %>":"A better fifth proposal"},"parent_documents":{"<%= Fixtures.identify('language_en') %>":"A second proposal!","<%= Fixtures.identify('language_de') %>":"Ein zweiter Vorschlag"},"parent_id":<%= Fixtures.identify('second-proposal')%>,"operation":"created","level":2,"top_level":false}'
+ event: <%= {:type => "improvement", :id => Fixtures.identify('fifth-impro-proposal'), :tags => [], :documents => {Fixtures.identify('language_en') => "A better fifth proposal"}, :parent_documents => {Fixtures.identify('language_en') => "A second proposal!", Fixtures.identify('language_de') => "Ein zweiter Vorschlag"},:parent_id => Fixtures.identify('second-proposal'),:operation => "created", :level => 2, :top_level => false}.to_yaml.inspect %>
subscribeable_id: <%= Fixtures.identify('second-proposal')%>
subscribeable_type: StatementNode
operation: new
View
4 test/fixtures/social_identifiers.yml
@@ -2,10 +2,10 @@ joe_facebook:
user_id: <%= Fixtures.identify(:joe) %>
provider_name: Facebook
identifier: @qwerfdglkngfd322@dfgnlkdfgfdlkegr
- profile_info: "it is supposed to be a string"
+ profile_info: <%= {:description => "it is supposed to be a string"}.to_yaml.inspect %>
no_pass_user_facebook:
user_id: <%= Fixtures.identify(:no_pass_user) %>
provider_name: Facebook
identifier: http://ilikeflowers.com
- profile_info: "give it up to big sexy!"
+ profile_info: <%= {:description => "give it up to big sexy!"}.to_yaml.inspect %>
View
8 test/functional/activations_controller_test.rb
@@ -40,7 +40,7 @@ def setup
u = users(:user)
p = PendingAction.new(:pending => u,
:action => {:email => "maingirl@g5.com",
- :email_confirmation => "maingirl@g5.com"}.to_json)
+ :email_confirmation => "maingirl@g5.com"})
p.save
p.reload
post :activate_email, :token => p.uuid
@@ -50,7 +50,7 @@ def setup
test "should not activate coming from the setup basic profile form with an unverified email" do
u = flexmock(User.create(:profile => Profile.new, :social_identifiers => [
SocialIdentifier.new(:identifier => "mi", :provider_name => "o2",
- :profile_info => {'email' => "main@main.com", 'preferredUsername' => "echo beach"}.to_json)]))
+ :profile_info => {:email => "main@main.com", :preferredUsername => "echo beach"})]))
assert_difference('ActionMailer::Base.deliveries.count', 1) do # activate email
post :activate, :activation_code => u.perishable_token,
:user => {:full_name => "Mad Max",
@@ -65,7 +65,7 @@ def setup
test "should not activate coming from the setup basic profile form with a used email" do
u = flexmock(User.create(:profile => Profile.new, :social_identifiers => [
SocialIdentifier.new(:identifier => "mi", :provider_name => "o2",
- :profile_info => {'email' => "main@main.com", 'preferredUsername' => "echo beach"}.to_json)]))
+ :profile_info => {:email => "main@main.com", :preferredUsername => "echo beach"})]))
assert_difference('ActionMailer::Base.deliveries.count', 0) do # activate email
post :activate, :activation_code => u.perishable_token,
:user => {:full_name => "Mad Max",
@@ -82,7 +82,7 @@ def setup
test "should activate coming from the setup basic profile form with a verified email" do
u = flexmock(User.new(:profile => Profile.new, :social_identifiers => [
SocialIdentifier.new(:identifier => "mi", :provider_name => "o2",
- :profile_info => {'verifiedEmail' => "main@main.com", 'preferredUsername'=> "echo beach"}.to_json)]))
+ :profile_info => {:verifiedEmail => "main@main.com", :preferredUsername => "echo beach"})]))
u.save
assert_difference('ActionMailer::Base.deliveries.count', 1) do #activation confirmation email
post :activate, :activation_code => u.perishable_token,
View
10 test/functional/users_controller_test.rb
@@ -7,10 +7,10 @@ class UsersControllerTest < ActionController::TestCase
def setup
# login_as :user
@controller = Users::UsersController.new
- profile_template = {'identifier' => "@asdas12dgfkj54oi",
- 'providerName' => "yahoy!",
- 'email' => "mymailprofile",
- 'preferredUsername' => "Chuck Norris"}
+ profile_template = {:identifier => "@asdas12dgfkj54oi",
+ :providerName => "yahoy!",
+ :email => "mymailprofile",
+ :preferredUsername => "Chuck Norris"}
flexmock(SocialService.instance).should_receive(:get_profile_info).with(:token).and_return(profile_template)
flexmock(SocialService.instance).should_receive(:map).with(String, Integer).and_return(nil)
flexmock(SocialService.instance).should_receive(:unmap).with(String, Integer).and_return(nil)
@@ -235,7 +235,7 @@ def setup
test "should load setup basic profile form for a new user" do
u = flexmock(User.create(:profile => Profile.new, :social_identifiers => [
SocialIdentifier.new(:identifier => "mi", :provider_name => "o2",
- :profile_info => {:email => "main@main.com", :preferredUsername => "echo beach"}.to_json)]))
+ :profile_info => {:email => "main@main.com", :preferredUsername => "echo beach"})]))
put :setup_basic_profile, :activation_code => u.perishable_token
assert_response :success
end
View
46 test/unit/activity_tracking_mailer_test.rb
@@ -15,7 +15,7 @@ class ActivityTrackingMailerTest < ActionMailer::TestCase
context "being sent an activity tracking email with question info" do
setup do
- @question_event = JSON.parse(events(:event_test_question).event)
+ @question_event = events(:event_test_question).event
question_events = [@question_event]
tags = {'#echonomyjam' => 1,'user' => 2}
@@ -29,8 +29,8 @@ class ActivityTrackingMailerTest < ActionMailer::TestCase
assert_equal "echo - New discussion content", @email.subject
assert_match /New discussion content/, @email.encoded
assert_match /1 new question/, @email.encoded
- assert_match /#{@question_event['documents'][Language['en'].id]}/, @email.encoded
- assert_match /#{@question_event['id']}/, @email.encoded
+ assert_match /#{@question_event[:documents][Language['en'].id]}/, @email.encoded
+ assert_match /#{@question_event[:id]}/, @email.encoded
assert_match /They are related to the following topics:/, @email.encoded
assert_match /user/, @email.encoded
assert_match /(2)/, @email.encoded
@@ -41,11 +41,11 @@ class ActivityTrackingMailerTest < ActionMailer::TestCase
setup do
question_events = []
tags = {}
- @proposal_event = JSON.parse(events(:event_second_proposal).event)
- events = {@proposal_event['level'] => {
- @proposal_event['parent_id'] => {
- @proposal_event['type'] => {
- @proposal_event['operation'] => [@proposal_event]}}} }
+ @proposal_event = events(:event_second_proposal).event
+ events = {@proposal_event[:level] => {
+ @proposal_event[:parent_id] => {
+ @proposal_event[:type] => {
+ @proposal_event[:operation] => [@proposal_event]}}} }
# Send the email, then test that it got queued
@email = ActivityTrackingMailer.deliver_activity_tracking_mail!(@user,question_events,tags,events)
@@ -56,9 +56,9 @@ class ActivityTrackingMailerTest < ActionMailer::TestCase
assert_equal [@user.email], @email.to
assert_equal "echo - New discussion content", @email.subject
assert_match /New discussion content/, @email.encoded
- assert_match /#{@proposal_event['parent_documents'][Language['en'].id]}/, @email.encoded
- assert_match /#{@proposal_event['id']}/, @email.encoded
- assert_match /#{@proposal_event['documents'][Language['en'].id]}/, @email.encoded
+ assert_match /#{@proposal_event[:parent_documents][Language['en'].id]}/, @email.encoded
+ assert_match /#{@proposal_event[:id]}/, @email.encoded
+ assert_match /#{@proposal_event[:documents][Language['en'].id]}/, @email.encoded
end
end
@@ -66,11 +66,11 @@ class ActivityTrackingMailerTest < ActionMailer::TestCase
setup do
question_events = []
tags = {}
- @impro_proposal_event = JSON.parse(events(:event_first_impro_proposal).event)
- events = {@impro_proposal_event['level'] => {
- @impro_proposal_event['parent_id'] => {
- @impro_proposal_event['type'] => {
- @impro_proposal_event['operation'] => [@impro_proposal_event]}}} }
+ @impro_proposal_event = events(:event_first_impro_proposal).event
+ events = {@impro_proposal_event[:level] => {
+ @impro_proposal_event[:parent_id] => {
+ @impro_proposal_event[:type] => {
+ @impro_proposal_event[:operation] => [@impro_proposal_event]}}} }
# Send the email, then test that it got queued
@email = ActivityTrackingMailer.deliver_activity_tracking_mail!(@user,question_events,tags,events)
@@ -81,9 +81,9 @@ class ActivityTrackingMailerTest < ActionMailer::TestCase
assert_equal [@user.email], @email.to
assert_equal "echo - New discussion content", @email.subject
assert_match /New discussion content/, @email.encoded
- assert_match /#{@impro_proposal_event['parent_documents'][Language['en'].id]}/, @email.encoded
- assert_match /#{@impro_proposal_event['id']}/, @email.encoded
- assert_match /#{@impro_proposal_event['documents'][Language['en'].id]}/, @email.encoded
+ assert_match /#{@impro_proposal_event[:parent_documents][Language['en'].id]}/, @email.encoded
+ assert_match /#{@impro_proposal_event[:id]}/, @email.encoded
+ assert_match /#{@impro_proposal_event[:documents][Language['en'].id]}/, @email.encoded
end
end
@@ -92,16 +92,16 @@ class ActivityTrackingMailerTest < ActionMailer::TestCase
ActivityTrackingService.instance.generate_activity_mail(@user.id)
end
should "not be able to access data from the private improvement" do
- @impro = JSON.parse(events(:event_closed_impro_proposal).event)
+ @impro = events(:event_closed_impro_proposal).event
assert !ActionMailer::Base.deliveries.empty?
@email = ActionMailer::Base.deliveries.last
# Test the body of the sent email contains what we expect it to
assert_equal [@user.email], @email.to
assert_equal "echo - New discussion content", @email.subject
assert_match /New discussion content/, @email.encoded
- assert_no_match /#{@impro['parent_documents'][Language['en'].id.to_s]}/, @email.encoded
- assert_no_match /#{@impro['id']}/, @email.encoded
- assert_no_match /#{@impro['documents'][Language['en'].id.to_s]}/, @email.encoded
+ assert_no_match /#{@impro[:parent_documents][Language['en'].id]}/, @email.encoded
+ assert_no_match /#{@impro[:id]}/, @email.encoded
+ assert_no_match /#{@impro[:documents][Language['en'].id]}/, @email.encoded
end
end
end
View
16 test/unit/shortcut_url_test.rb
@@ -11,7 +11,7 @@ class ShortcutUrlTest < ActiveSupport::TestCase
context "having been saved" do
setup do
- @shortcut_url = ShortcutUrl.find_or_create :shortcut => "This is the first statement title", :human_readable => true, :shortcut_command => {:command => "sten1"}
+ @shortcut_url = ShortcutUrl.find_or_create :shortcut => "This is the first statement title", :human_readable => true, :shortcut_command => {:command => {:operation => "sten1"}}
end
context "given we want to save a new shortcut with the same title" do
@@ -20,7 +20,7 @@ class ShortcutUrlTest < ActiveSupport::TestCase
end
should "create a new shortcut for a statement with the same title, but with the iterator being used at the end of it" do
- new_shortcut = ShortcutUrl.find_or_create :shortcut => @new_title, :human_readable => true, :shortcut_command => {:command => "sten2"}
+ new_shortcut = ShortcutUrl.find_or_create :shortcut => @new_title, :human_readable => true, :shortcut_command => {:command => {:operation => "sten2"}}
assert new_shortcut.valid?
assert !new_shortcut.eql?(@shortcut_url)
@@ -28,7 +28,7 @@ class ShortcutUrlTest < ActiveSupport::TestCase
end
should "create a new shortcut for the same statement" do
- new_shortcut = ShortcutUrl.find_or_create :shortcut => @new_title, :human_readable => true, :shortcut_command => {:command => "sten1"}
+ new_shortcut = ShortcutUrl.find_or_create :shortcut => @new_title, :human_readable => true, :shortcut_command => {:command => {:operation => "sten1"}}
assert new_shortcut.eql?(@shortcut_url)
assert new_shortcut.shortcut.eql? "this-is-the-first-statement-title"
@@ -38,7 +38,7 @@ class ShortcutUrlTest < ActiveSupport::TestCase
context "having been saved with a really long name" do
setup do
title = "This is really a long title because its supposed to be this way if you have problems with it buzz off"
- @shortcut_url = ShortcutUrl.find_or_create :shortcut => title, :human_readable => true, :shortcut_command => {:command => "sten1"}
+ @shortcut_url = ShortcutUrl.find_or_create :shortcut => title, :human_readable => true, :shortcut_command => {:command => {:operation => "sten1"}}
end
context "given we want to save a new shortcut with the same title" do
@@ -47,7 +47,7 @@ class ShortcutUrlTest < ActiveSupport::TestCase
end
should "create a new shortcut for a statement with the same title, therefore cutting the former" do
- new_shortcut = ShortcutUrl.find_or_create :shortcut => @new_title, :human_readable => true, :shortcut_command => {:command => "sten2"}
+ new_shortcut = ShortcutUrl.find_or_create :shortcut => @new_title, :human_readable => true, :shortcut_command => {:command => {:operation => "sten2"}}
assert !new_shortcut.eql?(@shortcut_url)
assert new_shortcut.shortcut.eql? "this-is-really-a-long-title-because-its-supposed-to-be-this-way-if-you-have-problems-with-it-buzz-of1"
@@ -61,7 +61,7 @@ class ShortcutUrlTest < ActiveSupport::TestCase
end
should "save the shortcut without the special characters" do
- @shortcut_url = ShortcutUrl.find_or_create :shortcut => @title, :human_readable => true, :shortcut_command => {:command => "sten2"}
+ @shortcut_url = ShortcutUrl.find_or_create :shortcut => @title, :human_readable => true, :shortcut_command => {:command => {:operation => "sten2"}}
assert @shortcut_url.shortcut, "o-cao-do-joao-roca-a-direita-do-pai"
end
@@ -71,7 +71,7 @@ class ShortcutUrlTest < ActiveSupport::TestCase
context "having been saved with a really big shortcut" do
setup do
@title = "O rato roeu a rolha do rei da Russia atirei o pau ao gato to mas o gato to nao morreu eu eu dona Xica ca assustou-se se com o berro que o gato deu"
- @shortcut_url = ShortcutUrl.find_or_create :shortcut => @title, :human_readable => true, :shortcut_command => {:command => "sten1"}
+ @shortcut_url = ShortcutUrl.find_or_create :shortcut => @title, :human_readable => true, :shortcut_command => {:command => {:operation => "sten1"}}
end
should "cut the title with the appropriate size" do
@@ -82,7 +82,7 @@ class ShortcutUrlTest < ActiveSupport::TestCase
context "having been saved with special characters" do
setup do
@title = "Mas quem sou eu? O bom, o mau ou o vilão?"
- @shortcut_url = ShortcutUrl.find_or_create :shortcut => @title, :human_readable => true, :shortcut_command => {:command => "sten1"}
+ @shortcut_url = ShortcutUrl.find_or_create :shortcut => @title, :human_readable => true, :shortcut_command => {:command => {:operation => "sten1"}}
end
should "cut the special characters" do
View
2  test/unit/statement_node_test.rb
@@ -62,7 +62,7 @@ class StatementNodeTest < ActiveSupport::TestCase
# should "have have a creation event associated" do
# @events = @statement_node.events
# assert(@events.first.operation.eql?('new'))
-# result = JSON.parse(@events.first.event)
+# result = @events.first.event
#
# question = result['question']
# statement = question['statement']
View
4 test/unit/user_test.rb
@@ -32,7 +32,7 @@ class UserTest < ActiveSupport::TestCase
should "not save unactive user without email, unless there's a social identifier" do
assert !User.new.save
- u = User.new(:social_identifiers => [SocialIdentifier.new(:identifier => "mi", :provider_name => "o2", :profile_info => "bling")])
+ u = User.new(:social_identifiers => [SocialIdentifier.new(:identifier => "mi", :provider_name => "o2", :profile_info => {:name => "bling"})])
assert u.save, u.errors.inspect
end
@@ -43,7 +43,7 @@ class UserTest < ActiveSupport::TestCase
should "save active user if password defined or if there's a social identifier" do
assert User.new(:email => "mainman@mainman.com", :password => "balls", :active => true).save
- u = User.new(:social_identifiers => [SocialIdentifier.new(:identifier => "mi", :provider_name => "o2", :profile_info => "bling")])
+ u = User.new(:social_identifiers => [SocialIdentifier.new(:identifier => "mi", :provider_name => "o2", :profile_info => {:name => "bling"})])
u.save
u.email = "singledout@mainman.com"
u.active = true
Please sign in to comment.
Something went wrong with that request. Please try again.