Sha256: 4f48bacb915f84115085c0d20b07e04171f8e9a9c6c9bb472a309e360be5fb1b

Contents?: true

Size: 1.74 KB

Versions: 22

Compression:

Stored size: 1.74 KB

Contents

class MessagesDataset < Dataset::Base
  datasets = [:readers, :users]
  datasets << :reader_sites if defined? Site
  uses *datasets

  def load
    create_message "Normal"
    create_message "Filtered", :filter_id => 'Textile', :body => 'this is a *filtered* message'
    create_message "Welcome", :filter_id => 'Textile', :body => 'Hi', :function_id => 'welcome'
    create_message "Activation", :filter_id => 'Textile', :body => 'Hi?', :function_id => 'activation'
    create_message "Invitation", :filter_id => 'Textile', :body => 'Hi!', :function_id => 'invitation'
    create_message "Password", :filter_id => 'Textile', :body => 'Oh', :function_id => 'password_reset'
    create_message "Taggy", :filter_id => 'Textile', :body => %{
To <r:recipient:name />

Ying Tong Iddle I Po.

From <r:sender:name />
    }
  end
  
  helpers do
    def create_message(subject, attributes={})
      attributes = message_attributes(attributes.update(:subject => subject))
      message = create_model Message, subject.symbolize, attributes
      message.update_attribute(:created_by, users(:existing))
    end
    
    def message_attributes(attributes={})
      subject = attributes[:subject] || "Message"
      symbol = subject.symbolize
      attributes = { 
        :subject => subject,
        :body => "This is the #{subject} message"
      }.merge(attributes)
      attributes[:site] = sites(:test) if defined? Site
      attributes
    end
    
    def seem_to_send(message, reader)
      message = messages(message) unless message.is_a?(Message)
      reader = readers(reader) unless reader.is_a?(Reader)
      sending = MessageReader.find_or_create_by_message_id_and_reader_id(message.id, reader.id)
      sending.sent_at = 10.minutes.ago
      sending.save
    end
  end
 
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
radiant-reader-extension-1.3.13 spec/datasets/messages_dataset.rb
radiant-reader-extension-1.3.12 spec/datasets/messages_dataset.rb
radiant-reader-extension-1.3.11 spec/datasets/messages_dataset.rb
radiant-reader-extension-1.3.10 spec/datasets/messages_dataset.rb
radiant-reader-extension-1.3.9 spec/datasets/messages_dataset.rb
radiant-reader-extension-1.3.8 spec/datasets/messages_dataset.rb
radiant-reader-extension-1.3.7 spec/datasets/messages_dataset.rb
radiant-reader-extension-1.3.6 spec/datasets/messages_dataset.rb
radiant-reader-extension-1.3.4 spec/datasets/messages_dataset.rb
radiant-reader-extension-1.3.3 spec/datasets/messages_dataset.rb
radiant-reader-extension-1.3.1 spec/datasets/messages_dataset.rb
radiant-reader-extension-1.3.0 spec/datasets/messages_dataset.rb
radiant-reader-extension-1.2.4 spec/datasets/messages_dataset.rb
radiant-reader-extension-1.2.3 spec/datasets/messages_dataset.rb
radiant-reader-extension-1.2.2 spec/datasets/messages_dataset.rb
radiant-reader-extension-1.2.1 spec/datasets/messages_dataset.rb
radiant-reader-extension-1.2.0 spec/datasets/messages_dataset.rb
radiant-reader-extension-1.1.1 spec/datasets/messages_dataset.rb
radiant-reader-extension-1.1.0 spec/datasets/messages_dataset.rb
radiant-reader-extension-1.0.1 spec/datasets/messages_dataset.rb