<commit_before>require 'spec_helper'

describe Notifiable::Mpns::Nverinaud::SingleNotifier do
  
  let(:m) { Notifiable::Mpns::Nverinaud::SingleNotifier.new }
  let(:n) { Notifiable::Notification.create(:message => "Test message") }
  let(:d) { Notifiable::DeviceToken.create(:token => "http://db3.notify.live.net/throttledthirdparty/01.00/123456789123456798", :provider => :mpns) }
  let(:u) { User.new(d) }
  
  it "sends a single mpns notification" do    
    stub_request(:post, d.token)
         
    m.send_notification(n, d)
    m.close
    
    Notifiable::NotificationDeviceToken.count.should == 1
  end
  
  it "de-registers a device on receiving a 404 status from MPNS" do    
    stub_request(:post, d.token).to_return(:status => 404)
         
    m.send_notification(n, d)
    m.close
    
    Notifiable::NotificationDeviceToken.count.should == 0
    Notifiable::DeviceToken.first.is_valid.should == false
  end
  
end<commit_msg>Update spec for new notifiable-rails<commit_after>require 'spec_helper'

describe Notifiable::Mpns::Nverinaud::SingleNotifier do
  
  let(:m) { Notifiable::Mpns::Nverinaud::SingleNotifier.new }
  let(:d) { Notifiable::DeviceToken.create(:token => "http://db3.notify.live.net/throttledthirdparty/01.00/123456789123456798", :provider => :mpns) }
  let(:u) { User.new(d) }
  
  it "sends an mpns notification with a title" do
    n = Notifiable::Notification.create(:payload => {:mpns => {:title => "A title"}})   

    stub_request(:post, d.token)
         
    m.send_notification(n, d)
    m.close
    
    Notifiable::NotificationDeviceToken.count.should == 1
    a_request(:post, d.token)
      .with(:body => "<?xml version=\"1.0\" encoding=\"UTF-8\"?><wp:Notification xmlns:wp=\"WPNotification\"><wp:Toast><wp:Text1>A title</wp:Text1><wp:Text2></wp:Text2><wp:Param></wp:Param></wp:Toast></wp:Notification>")
      .should have_been_made.once
  end
  
  it "sends a single mpns notification with content" do
    n = Notifiable::Notification.create(:message => "A message")   
    stub_request(:post, d.token)
         
    m.send_notification(n, d)
    m.close
    
    Notifiable::NotificationDeviceToken.count.should == 1
    a_request(:post, d.token)
      .with(:body => "<?xml version=\"1.0\" encoding=\"UTF-8\"?><wp:Notification xmlns:wp=\"WPNotification\"><wp:Toast><wp:Text1></wp:Text1><wp:Text2>A message</wp:Text2><wp:Param></wp:Param></wp:Toast></wp:Notification>")
      .should have_been_made.once
  end
  
  it "sends custom attributes" do 
    n = Notifiable::Notification.create(:payload => {:mpns => {:params => {:an_object_id => 123456}}})    
    
    stub_request(:post, d.token) 
         
    m.send_notification(n, d)
    m.close
    
    Notifiable::NotificationDeviceToken.count.should == 1
    a_request(:post, d.token)
      .with(:body => "<?xml version=\"1.0\" encoding=\"UTF-8\"?><wp:Notification xmlns:wp=\"WPNotification\"><wp:Toast><wp:Text1></wp:Text1><wp:Text2></wp:Text2><wp:Param>?an_object_id=123456</wp:Param></wp:Toast></wp:Notification>")
      .should have_been_made.once
  end
  
  it "de-registers a device on receiving a 404 status from MPNS" do
    n = Notifiable::Notification.create(:message => "A message")   
        
    stub_request(:post, d.token).to_return(:status => 404)
         
    m.send_notification(n, d)
    m.close
    
    Notifiable::NotificationDeviceToken.count.should == 0
    Notifiable::DeviceToken.first.is_valid.should == false
  end
  
end
{'fraction_non_alphanumeric': 0.16151401329095638, 'fraction_numerical': 0.02802658191274198, 'mean_word_length': 3.768595041322314, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 3, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5690628', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1170, 'n_words': 194}